ES6语法-class类写法
//network文件夹下的detail.js文件
//export导出,constructor构造器里面可以放一些参数
1 export class Goods {
2 constructor(itemInfo, columns, services) {
3 this.title = itemInfo.title;
4 this.desc = itemInfo.desc;
5 this.newPrice = itemInfo.price;
6 this.oldPrice = itemInfo.oldPrice;
7 this.discount = itemInfo.discountDesc;
8 this.columns = columns;
9 this.services = services;
10 this.realPrice = itemInfo.lowNowPrice;
11 }
12 }
//vue组件
<script>
//导入Goods类
import { Goods } from "network/detail";
data() {
return {
goods: {}
};
},
created() {
getDetail().then(res => {
const data = res.result;
//使用Goods类
goods = new Goods(data.itemInfo,data.columns,data.shopInfo.services);
});
},
</script>
注:以上内容仅用于日常学习