Categories
Vue Answers

How to get Vuex state from a JavaScript file with Vue.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *