Currently, I am diving into the world of Vuex and encountering some challenges along the way. In my attempt to create a getter
on my vuex instance, I am facing an error when trying to display data from one of my components:
The getter should be a function but instead "getters.doubleCounter" is showing as 20.
store.js
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
counter: 10
},
getters: {
doubleCounter: state => {
return state.counter * 2;
}
}
});
MY COMPONENT:
<template>
<div>
<p>This message is from services.</p>
<button v-on:click="increment">+</button>
<button v-on:click="decrement">-</button>
{{ counter }}
</div>
</template>
<script>
export default {
computed: {
counter() {
return this.$store.getters.doubleCounter;
},
},
methods: {
increment: function () {
this.$store.state.counter++
},
decrement: function () {
this.$store.state.counter--
}
}
}
</script>
Once again, upon attempting to render the page containing this component, it fails and displays the aforementioned error message in the console. Any assistance would be immensely appreciated! Thank you!