从Vuex中取出数组赋值给新的数组,新数组push时报错的解决方法
如下所示:
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(),不会修改原始数组而是返回一个新数组
相关推荐
CSCCockroach 2020-09-15
lbPro0 2020-07-05
MrSunOcean 2020-06-21
lylwanan 2020-06-14
Callmesmallpure 2020-05-31
ShaLiWa 2020-05-25
墨龙吟 2020-04-24
MrSunOcean 2020-04-24
H女王范儿 2020-04-22
lbPro0 2020-04-16
ShaLiWa 2020-02-29
ShaLiWa 2020-01-17
MrSunOcean 2020-01-03
lbPro0 2020-01-01
H女王范儿 2019-12-29