goods: (流行/新款/精选)
goods: {
‘pop’: {page : 1, list: []},
‘news’: {},
‘sell’: {}
}
// 数据请求的封装
created() {
//1. 请求多个数据
this.getHomeMultidata();
//2. 请求商品数据
this.getHomeGoods('pop');
this.getHomeGoods('new');
this.getHomeGoods('sell');
},
methods: {
getHomeMultidata() {
getHomeMultidata().then(res => {
console.log(res);
this.banners = res.data.banner.list;
this.recommends = res.data.recommend.list;
});
},
getHomeGoods(type) {
const page = this.goods[type].page + 1;
getHomeGoods(type,page).then(res=>{
console.log(res);
this.goods[type].list.push(res.data.list);
this.goods[type].page += 1;
})
}
}