怎样才能获取到数据。老是报错
product > slider.vue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | < template > < me-loading v-if = "!sliders.length" /> < me-slider :data = "sliders" :direction = "direction" :loop = "loop" :interval = "interval" :pagination = "pagination" v-else > < swiper-slide v-for = "(item, index) in sliders" :key = "index" > < a :href = "item.linkUrl" alt = "" class = 'slider-link' > < img :src = "item.picUrl" alt = "" class = 'slider-img' > </ a > </ swiper-slide > </ me-slider > </ template > < script > import MeSlider from 'base/slider'; import {swiperSlide} from 'vue-awesome-swiper'; import {getProductDetail,getGoodsDetails} from 'api/product'; import MeLoading from 'base/loading'; // import {sliderOptions} from './config'; export default{ name: 'HomeSlider', components: { MeSlider, MeLoading, swiperSlide }, data(){ return{ direction: "horizontal", loop: true, interval: 0, pagination:true, sliders: [] } }, created() { // this.getSliders(); // this.getRecommend() // getGoodsDetails(this.$route.params.id) getGoodsDetails(594415289458) }, methods:{ update() { return this.getSliders(); }, getproduct(){ return getGoodsDetails().then(data=>{ console.log(data) }) } } }; </ script > < style > .slider-wapper { width: 100%; height: 183px; } .slider-link { display: block; } .slider-link, .slider-img { overflow: hidden; width: 100%; height: 100%; } </ style > |
api > product.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import jsonp from 'jsonp' import {jsonpOptions} from './config' export const getGoodsDetails = (id) => { const url = 'https://unszacs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/' ; const params = { api: 'mtop.taobao.detail.getdetail' , ttid: '2017@40taobao_h5_6.6.0' , data: `{ "itemNumId" : "${id}" }`, appkey: '12574478' , dataType: 'jsonp' , type: 'jsonp' , v: '6.0' }; console.log(url) return jsonp(url, params,jsonpOptions).then(res=>{ console.log(res) console.log(url) }) } |
0
收起
正在回答
4回答
你好,可以不传固定的id值,点击商品传入相应的id:
测试出来是有结果的:
可以重新启动项目试一下。
祝学习愉快!
热门框架Vue开发WebApp 18版
- 参与学习 人
- 提交作业 209 份
- 解答问题 3299 个
本路径是通过ES6基础知识、运用Zepto、Swiper、fullPag等移动端常用工具包、以及当下流行框架Vue,结合多个实战案例,还原真实开发场景,最终实现手机端购物商城网页开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧