Callmesmallpure 2018-09-18
如下所示:
Uncaught Error: [vuex] Do not mutate vuex store state outside mutation handlers
今天遇到一个问题,将Vuex中数组的值赋给新的数组,新数组push时报上面的错误,代码如下
<code class="language-javascript">this.maPartListTable = this.$store.state.vehicleMa.maPartListTable; </code>
this.maPartListTable.push(obj);
经询问后得知,应该这么写
this.maPartListTable = this.$store.state.vehicleMa.maPartListTable.slice();
查了下,就查到这句
slice(),不会修改原始数组而是返回一个新数组