【发布时间】:2020-05-15 17:40:22
【问题描述】:
/pages/index.vue
computed: {
escapeValues() { return this.$store.state.escapeOnline.splice(0, 1); }
}
/store/index.js
export const state = () => ({
escapeOnline: [{id: 1, name: 'titi'}, {id: 2, 'toto'}],
})
当我尝试运行我的 /pages/index.vue 时,我无法保留数组的第一个元素。
我有这个错误:[vuex] Do not mutate vuex store state outside mutation handlers.
【问题讨论】:
-
splice改变它所操作的数组。这就是您收到此错误的原因。尝试使用slice或不会改变原始数组的方法。