Reputation: 17467
I have a global store setting which determines which user role could be 'admin', 'editor' or 'junior-editor'.
A the moment I have to import my store and use make the store variable available in the data.
Is there a way to expose this al all my components?
Upvotes: 0
Views: 1031
Reputation: 2529
If using Vuex, you can call it on any component using: this.$store
For example, in an app with a "user" module and the data is called "role", it would be:
this.$store.state.user.role
There is no need to import store into each component. It should be injected in your main app file (main.js or index.js), like:
new Vue({
el: '#app',
router,
store
})
Upvotes: 1