[Vuejs]-Vue.js use method of undefined

1👍

Store.js:

import { createStore } from 'vuex'

export default createStore({

state: {...},
mutations: {...},
action: {...},
getters: {...}

})

main.js


import App from './App.vue'
import { createApp } from 'vue'
import store from './store'

createApp(App)    
    .use(store)    
    .mount('#app')

2👍

If you’re using Vue 3, it doesn’t support global config. You’ll need to do it like this I think:

import { createApp } from 'vue';
import { createStore } from 'vuex';

const store = createStore(
  // options
);

const app = createApp(
  // options
);

app.use(store);

Also you will need to upgrade to vuex@4 for Vue 3 support.

👤Hannah

0👍

Move

import Vue from 'vue';
import Vuex from 'Vuex';

to main.js
since you need to call before its initialize

Leave a comment