【发布时间】:2020-08-31 11:18:23
【问题描述】:
当我尝试更改组件的输入文本时,我在控制台中收到此错误:
[vuex] 不要在突变处理程序之外改变 vuex 存储状态
我也将 nuxt 与 vuex 一起使用。
我的店里有这个:
editor.js
export const state = () => ({
project_blocks: [{
id: null,
type: 'text-right',
content:{
title: 'Title 2',
text: 'Text 2',
}
},{
id: null,
type: 'text-left',
content:{
title: 'Title 1',
text: 'Text 1',
}
}],
});
export const mutations = {
SET_BLOCKS(state, blocks){
state.project_blocks = blocks;
},
};
export const getters = {
project_blocks(state){
return state.project_blocks;
}
};
在我的组件中我有:
Index.vue
<template>
<component v-for="(block, index) in project_blocks" :key="'module'+index" :block="block" :is="block.type"></component>
</template>
<script>
export default{
computed: {
project_blocks:{
get(){
return this.$store.getters['editor/project_blocks'];
},
set(val){
this.$store.commit('editor/SET_BLOCKS', val);
}
},
}
}
</script>
在我的“组件类型”中,我有:
TextLeft.vue
<template>
<input type="text" v-model="block.content.title">
<input type="text" v-model="block.content.text">
</template>
<script>
export default{
props:['block']
}
</script>
当我尝试更改这些输入文本的文本时,我收到此错误:[vuex] do not mutate vuex store state outside mutation handlers 我不知道如何修复它:(
谢谢大家!
【问题讨论】: