How do I access the Vuex store in Vue when using the setup()
method?
I don't have access to the regular this.$store
variable anymore.
How do I access the Vuex store in Vue when using the setup()
method?
I don't have access to the regular this.$store
variable anymore.
According to the composition API documentation you have to use the following syntax:
import { computed } from 'vue' // If not already imported
import { useStore } from 'vuex'
export default {
setup () {
const store = useStore()
return {
// access a state in computed function
count: computed(() => store.state.count),
// access a getter in computed function
double: computed(() => store.getters.double)
}
}
}
© 2022 - 2024 — McMap. All rights reserved.