解决思路:创建一个类,将想要贵到一起的数据传入类中
- 创建类,并传入要整合的数据,给类添加属性,并给属性赋值
1 2 3 4 5 6 7 8 9 10 11 12
| 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; } }
|
- 在对应的文件中引入导出的类,并实例化进行使用
1
| import {Goods } from "1.中的类所在的文件路径";
|
1 2 3 4 5 6 7 8
| getDetail(this.iid).then((res) => { this.goods = new Goods( res.result.itemInfo, res.result.columns, res.result.shopInfo.services ); });
|