在Vue的data里面设置一个商品版本数组时候,后面push时,需要注意数组是引用类型,push完后需要初始化
data: {
good_list: [],
good_name: '',//商品名称
ver_list: [{ //版本列表
ver_info: '',//版本信息
ver_price: '',//版本价格
ver_color: [{ //版本颜色
color: '',
ku: ''
}]
}]
},
created: function () {
this.good_list = JSON.parse(localStorage.getItem('good_list'));
},
methods: {
save_good: function () {
this.good_list.push({
name: this.good_name,
ver_list: this.ver_list
});
console.log(this.good_list)
// this.good_name = null
// this.ver_list = [{ //版本列表
// ver_info: '',//版本信息
// ver_price: '',//版本价格
// ver_color: [{ //版本颜色
// color: '',
// ku: ''
// }]
// }]
localStorage.setItem('good_list', JSON.stringify(this.good_list));//商品列表
},