Home

Issue: 2005

Accessing the store from an external file

[issue link]
// ~/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)?

This question is available on Nuxt.js community (#c1780)