老师我的数据获取不成功
product:index.vue
<template>
<div class="product">
<header class="g-header-container">
<product-header/>
</header>
<me-scroll>
<product-slider/>
</me-scroll>
</div>
</template>
<script>
import MeScroll from 'base/scroll';
import ProductHeader from './header';
import ProductSlider from './slider';
import {getProduct} from 'api/product';
export default {
name: 'home-product',
components:{
MeScroll,
ProductHeader,
ProductSlider
},
data(){
return {
}
},
created() {
console.log(this.$route.params.id);
getProduct(this.$route.params.id).then(data => {
console.log(data);
});
}
};
</script>
<style lang="scss" scoped>
@import "~assets/scss/mixins";
.product {
overflow: hidden;
position:absolute;
top: 0;
left: 0;
z-index: $product-z-index;
width: 100%;
height: 100%;
background-color: $bgc-theme;
}
</style>
product.js:
import jsonp from 'assets/js/jsonp';
import {jsonpOptions} from './config';
//获取搜索结果数据---jsonp
export const getProduct = id => {
const url='https://unszacs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/';
const params = {
api:'mtop.taobao.detail.getdetail',
ttid:'2017@taobao_h5_6.6.0',
data: `{"itemNumId":"${id}"}`,
appKey:12574478,
dataType:'jsonp',
type:'jsonp',
v:'6.0'
};
return jsonp(url, params, jsonpOptions).then(res => {
if (res.data) {
return res.data;
}
throw new Error('没有成功获取到数据!');
}).catch(err => {
if(err) {
// 有错误打印出来不处理
console.log(err);
}
}).then(res => {
// 延时一秒
return new Promise(resolve => {
setTimeout(() => {
resolve(res);
},1000);
});
});
};
断网的时候,可以看到获取是有的
https://unszacs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?api=mtop.taobao.detail.getdetail&ttid=2017@taobao_h5_6.6.0&data={%22itemNumId%22:%2240651415322%22}&appKey=12574478&dataType=jsonp&type=jsonp&v=6.0&callback=__jp6
有效的应该这样:上边的不能访问,html编码没转化一些字符,如@,{},:
当然本身断网了;下边是修改后可以访问的值
https://unszacs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?api=mtop.taobao.detail.getdetail&ttid=2017%40taobao_h5_6.6.0&data=%7b%22itemNumId%22%3A%2240651415322%22%7d&appKey=12574478&dataType=jsonp&type=jsonp&v=6.0&callback=__jp5
正在回答 回答被采纳积分+1
header:
<template>
<me-navbar class="header">
<i
class="iconfont icon-back"
slot="left"
@click="goBack"
></i>
<h3 class="title" slot="center">商品详情</h3>
<i class="iconfont icon-msg" slot="right"></i>
</me-navbar>
</template>
<script>
import MeNavbar from 'base/navbar';
export default {
name: 'ProductHeader',
components:{
MeNavbar
},
methods:{
goBack(){
this.$router.back();
},
}
};
</script>
<style lang="scss" scoped>
@import "~assets/scss/mixins";
.header {
&.mine-navbar {
background-color: $header-bgc-translucent;
}
.title {
text-align: center;
font-size: 16px;
color: #ffffff;
font-weight: bold;
}
.iconfont {
color: $icon-color-default;
font-size: $icon-font-size;
}
}
</style>
slider.vue:
<template>
<div class="slider-wrapper">
<!-- <me-loading v-if="!sliders.length"/>-->
<me-slider
:data="sliders"
:direaction="direction"
:loop="loop"
:interval="interval"
:pagination="pagination"
>
<swiper-slide
v-for="(item, index) in sliders"
:key="index"
>
<a :href="item.link" class="slider-link">
<img :src="item.picUrl" alt="" class="slider-img">
</a>
</swiper-slide>
</me-slider>
</div>
</template>
<script>
import MeSlider from 'base/slider';
import MeLoading from 'base/loading';
import {swiperSlide} from 'vue-awesome-swiper';
import {sliderOptions} from './config';
import {getProduct} from 'api/product';
export default {
name: 'ProductSlider',
components:{
MeSlider,
MeLoading,
swiperSlide
},
data() {
return {
direction: sliderOptions.direction,
loop: sliderOptions.loop,
interval: sliderOptions.interval,
pagination: sliderOptions.pagination,
sliders:[]
};
},
created() {
console.log(this.$route.params.id);
getProduct(this.$route.params.id).then(data => {
console.log('1');
});
// this.getSliders();
},
// methods:{
// update(){
// return this.getSliders();
// },
// getSliders(id) {
// return getProduct(this.$route.params.id).then(data => {
// // this.sliders = data;
// console.log(data);
// });
// }
// }
};
</script>
<style lang="scss" scoped>
.slider-wapper {
width: 100%;
height: 183px;
}
.slider-link {
display: block;
}
.slider-link,
.slider-img {
overflow: hidden;
width: 100%;
height: 100%;
}
</style>
- 参与学习 人
- 提交作业 209 份
- 解答问题 3299 个
本路径是通过ES6基础知识、运用Zepto、Swiper、fullPag等移动端常用工具包、以及当下流行框架Vue,结合多个实战案例,还原真实开发场景,最终实现手机端购物商城网页开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星