1、报错代码
[vuex] must call Vue.use(Vuex) before creating a store instance.
2、翻译
必须在创建store之前应用vuex
3、解决方法
① 先引用vuex插件
import Vuex from "vuex";
② 再使用vuex
Vue.use(Vuex)
③ 通过vuex创建store
new Vuex.Store({...})
④ vuex最终文件内容
//引入vue
import Vue from "vue";
//引入vuex库
import Vuex from "vuex";
// 使用vuex
Vue.use(Vuex)
//actions用于响应组件中用户的动作
const actions ={};
//mutations用于修改数据(state)
const mutations ={};
//state保存具体的数据
const state = {};
//store管理以上三个对象,并暴露store
export default new Vuex.Store({
actions,
mutations,
state
})