I get this error in my console when I try to change the text of an input text of my components:
[vuex] do not mutate vuex store state outside mutation handlers
I also use nuxt with vuex.
I have this in my store:
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;
}
};
In my component I have:
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>
And in my "component type" I have:
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>
When I try to change the text of these input text I get this error: [vuex] do not mutate vuex store state outside mutation handlers and I don't know how to fix it :(
Thanks people!