您的位置:首页 > 产品设计 > UI/UE

从Vuex中取出数组赋值给新的数组,新数组push时报错

2016-12-07 13:18 405 查看
Uncaught Error: [vuex] Do not mutate vuex store state outside mutation handlers

今天遇到一个问题,将Vuex中数组的值赋给新的数组,新数组push时报上面的错误,代码如下

this.maPartListTable = this.$store.state.vehicleMa.maPartListTable;


this.maPartListTable.push(obj);


经询问后得知,应该这么写

this.maPartListTable = this.$store.state.vehicleMa.maPartListTable.slice();

查了下,就查到这句
slice()
,不会修改原始数组而是返回一个新数组
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vue vuex 前端