[Solved] Vuex reports an error: [vuex] must call Vue.use(Vuex) before creating a store instance. Solution

1, error code

[vuex] must call Vue.use(Vuex) before creating a store instance.

2, translation

vuex must be applied before store creation

3. Solutions

① First refer to the vuex plugin
import Vuex from "vuex";
② Use vuex again
Vue.use(Vuex)
③ Create a store through vuex
new Vuex.Store({...})
④ vuex final file content

//Introduce vue
import Vue from "vue";

//Introduce vuex library
import Vuex from "vuex";

// use vuex
Vue.use(Vuex)

//actions is used to respond to the user's actions in the component
const actions ={<!-- -->};

//mutations are used to modify data (state)
const mutations ={<!-- -->};

//state saves specific data
const state = {<!-- -->};

//store manages the above three objects and exposes the store
export default new Vuex.Store({<!-- -->
    actions,
    mutations,
    state
})