Vue从object中删除所有类原型方法

时间:2018-05-14 01:44:09

标签: javascript vue.js

我在这里遗漏了什么吗?我有一个Class用于实例化和创建对象。这些对象具有原型方法。

let item = {
  name: 'Television',
  brand: 'Sony'
}

class Product {
  constructor (item) {
    Object.assign(this, item)
  }

  analyzeBrand () {
    // do something here
  }
}

let product1 = new Product(item);

然后在我的store中,我将此产品添加到数组

commit('addProduct', product1)

mutations: {
  addProduct (item) {
    state.products.unshift(item);
  }
}

但是当我稍后在Vue组件中检查我的产品实例时,原型方法analyzeBrand已被删除。是什么给了什么?

0 个答案:

没有答案