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>

  

posted @ 2020-07-28 16:31  Wayhome'  阅读(570)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css