如下所示:
Uncaught Error: [vuex] Do not mutate vuex store state outside mutation handlers
今天遇到一個問題,將Vuex中數(shù)組的值賦給新的數(shù)組,新數(shù)組push時報上面的錯誤,代碼如下
<code class="language-javascript">this.maPartListTable = this.$store.state.vehicleMa.maPartListTable; </code>
this.maPartListTable.push(obj);
經(jīng)詢問后得知,應(yīng)該這么寫
this.maPartListTable = this.$store.state.vehicleMa.maPartListTable.slice();
查了下,就查到這句
slice(),不會修改原始數(shù)組而是返回一個新數(shù)組
以上這篇從Vuex中取出數(shù)組賦值給新的數(shù)組,新數(shù)組push時報錯的解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答