I want to change a Vuex State with a computed function like in the documentation, but it didn't change and the console gives this error.
[Vue warn]: Write operation failed: computed property "renameActive" is readonly.
Im working with the VueCLI in Tauri.js.
Add new Tab Vue Component:
<template>
<div >
<div >All</div>
<Icons
:customClass="'addTab'"
:icon="'plus'"
@triggered="AddTab" />
<RenameField v-if="renameActive" />
</div>
</template>
<script>
import Icons from '@/components/Assets/Icons.vue'
import RenameField from '@/components/Popups/RenameField.vue'
export default {
components: {
Icons,
RenameField
},
computed: {
renameActive() {
return this.$store.state.renameActive
}
},
methods: {
AddTab() {
this.renameActive = true
}
}
}
</script>
<style lang="">
</style>
src/store/index.js
import { createStore } from 'vuex'
export default createStore({
state: {
navbar: [
"upload", "folder", "reset", "settings", "about"
],
currentTab: "All",
renameActive: false,
},
getters: {
},
mutations: {
},
actions: {
},
modules: {
}
})
src/main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
createApp(App).use(store).use(router).mount('#app')
How I can make it writeable?
CodePudding user response:
You can create mutation in your vuex store
mutateActive: (state, val) => (state.renameActive = val),
and vuex action that you will call:
setActive({ commit }, val) {
commit('mutateActive', val);
},
and in your method call vuex action and pass the value:
addTab() {
this.$store.dispatch('setActive', true)
}