开发中的各种奇怪问题
明明没有修改store值却有do not mutate vuex store state outside mutation handlers报错
// 代码取store的值
const newData = computed(() => store.state.newData)
// 然后页面报错
// do not mutate vuex store state outside mutation handlers
// 这时候可以这样修改
// 目的是把store赋值新对象
const newData = computed(() => { return { ...store.state.newData }})
// 如果这时候有这个错误
// Write operation failed: computed value is readonly.
// 可以这样修改
// 修改computed只能获取值
const newData = computed({
get() {
// 需要重新赋值
return { ...store.state.newData }
},
set() {}
})
这样你的问题基本解决了