在一個購物車列表中,購物車數(shù)據(jù)來自于 store, 我通過 vm.$set() 給數(shù)組每一項添加一個新的屬性 isChecked 來關(guān)聯(lián)每一項的選中狀態(tài)。computed: { cartBooks: function() { var carts = this.$store.getters.getCartBookList; if (carts.length > 0) { carts.forEach((item, index, array) => { this.$set(item, 'isChecked', true); }); } else { this.isCheckedAll = false; } return carts; } }但是卻報錯:"Error: [vuex] Do not mutate vuex store state outside mutation handlers."請問是否因為 store 中的數(shù)據(jù)只能通過 mutations 方法來修改,但我在 mutation 之外又通過 vm.$set() 來修改了 store 中的數(shù)據(jù)才出現(xiàn)這種錯誤呢?這種錯誤要如何處理呢?
使用 Vue.set() 操作 store 中的數(shù)據(jù)報錯
冉冉說
2018-12-13 18:14:47