Lets say my vuex store looks like this:
var store = new Vuex.Store({
state: {
enabled: true
},
mutations: {
TOGGLE (state) {
state.enabled = !state.enabled
}
}
})
Now when I declare my component in HTML I use:
<my-component v-show="store.state.enabled"></my-component>
I tried this and it didn't work.
Is there any way to access store.state.enabled directly?
I had to use a computed property which seemed more verbose than I was expecting.
computed: {
StoreStateEnabled () {
return store.state.enabled
}
}
this.$store is injected to components so you can just use $store in templates.
I don't think this is true anymore, I can use $store in my template and it works.
Most helpful comment
this.$store is injected to components so you can just use $store in templates.