// ~/store/index.js
import Vuex from 'vuex';
export default () => new Vuex.Store({
actions: {
someAction() {
//
}
}
});
// external js file
import store from '~/store';
export default class AuthService {
static login() {
store.dispatch('someAction');
}
}
I get an error when app builds:
TypeError: __WEBPACK_IMPORTED_MODULE_2__store__.default.dispatch is not a function
at AuthService.js:10
at <anonymous>
How can I dispatch an action of vuex in an external js file (not vue component)?
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1780">#c1780</a>)</em></sub></div>