发表于: 2020-05-14 20:33:30
1 1813
今天完成的事情:
1.推进任务
明天计划的事情:
1.推进任务
遇到的问题和收获
如果请求回来的数据非常的多,非常的乱。一般都是在data里面定义很多数据,然后请求回来的再赋值,如果需要props传值,那么会非常复杂
// 封装Detail请求数据后从res拿到的数据
export class Goods {
constructor(itemInfo, columns, services) {
this.title = itemInfo.title
this.desc = itemInfo.desc
this.newPrice = itemInfo.price
this.oldPrice = itemInfo.oldPrice
this.discount = itemInfo.discountDesc
this.columns = columns
this.services = services
this.realPrice = itemInfo.lowNowPrice
}
}
所以可以将请求回来的数据封装起来,一一赋值完毕。
使用的时候将请求回来的对应类型数据传进来即可
getDetail(this.iid).then(res => {
console.log(res);
//获取顶部轮播图数据
const data = res.result
this.topImages = data.itemInfo.topImages
//获取商品信息
this.goods = new Goods(data.itemInfo, data.columns, data.shopInfo.services)
})
这里用了构造函数。我需要看一下理解一下
判断对象是否为空
Object.keys(goods).length !== 0
评论