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

来源:互联网 发布:microsoft画图软件 编辑:程序博客网 时间:2024/05/07 12:41
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(),不会修改原始数组而是返回一个新数组

0 0
原创粉丝点击