Sometimes, we want to get Vuex state from a JavaScript file with Vue.js.
In this article, we’ll look at how to get Vuex state from a JavaScript file with Vue.js.
How to get Vuex state from a JavaScript file with Vue.js?
To get Vuex state from a JavaScript file with Vue.js, we can import the Vuex store and use it directly.
For instance, we write
import { store } from "../store";
export function getAuth() {
return store.state.authorization.AUTH_STATE;
}
to import the store
from a module.
Then we get a state value from the store with store.state.authorization.AUTH_STATE
.
Conclusion
To get Vuex state from a JavaScript file with Vue.js, we can import the Vuex store and use it directly.