4-2 热卖推荐获取数据出错

4-2 热卖推荐获取数据出错

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
import axios from 'axios'
import { SUCC_CODE, TIMEOUT, HOME_RECOMMEND_PAGE_SIZE, jsonpOptions } from './config'
 
import jsonp from 'assets/js/jsonp'
 
export const getHomeSlider = () => {
return axios.get('http://www.imooc.com/api/home/slider', {
timeout: TIMEOUT
}).then(res => {
console.log(res)
if (res.data.code === SUCC_CODE) {
return res.data.slider;
}
 
throw new Error('没有成功获取数据');
}).catch(err => {
if (err) {
console.log(err)
}
 
return [{
linkUrl: 'http://www.imooc.com',
picUrl: require('assets/img/404.png')
}]
}).then(data => {
return new Promise(resolve => {
setTimeout(() => {
resolve(data)
}, 1000)
})
})
}
 
export const getHomeRecommend = (page = 1, psize = HOME_RECOMMEND_PAGE_SIZE) => {
const url = 'https://ju.taobao.com/json/tg/ajaxGetItemsV2.json';
const params = {
page,
psize,
type: 0,
frontCatId: ''
};
 
return jsonp(url, params, jsonpOptions).then(res => {
if (res.code === '200') {
return res;
}
 
throw new Error('没有成功获取到数据!');
}).catch(err => {
if (err) {
console.log(err);
}
}).then(res => {
return new Promise(resolve => {
setTimeout(() => {
resolve(res);
}, 1000);
});
});
};
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
<template>
<div>
homeRecommend
</div>
</template>
 
<script>
import {getHomeRecommend} from 'api/home';
 
export default {
name: 'HomeRecommend',
data() {
return {
recommends: [],
curPage: 1,
tatalPage: 1
}
},
created() {
this.getRecommend();
},
methods: {
getRecommend() {
if (this.curPage > this.totalPage) {
return;
}
 
getHomeRecommend(this.curPage).then(data => {
if(data) {
console.log(data);
this.curPage++;
this.totalPage = data.totalPage;
this.recommends = this.recommends.concat(data.itemList);
}
})
}
}
}
</script>

http://img1.sycdn.imooc.com//climg/5d2488b50001041002990167.jpg4-2 热卖推荐获取数据出错

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
慕妹3422169 2019-08-01 13:46:30

我也和你一样,后来解决了吗

好帮手慕言 2019-07-10 10:47:15

同学你好,老师使用同学提供的代码是可以请求到数据的。

http://img1.sycdn.imooc.com//climg/5d2550520001876408910241.jpg

建议同学清除一下缓存,重新启动项目测试一下,祝学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码