【问题标题】:vuex must call Vue.use(Vuex) before creating a store instancevuex 必须在创建 store 实例之前调用 Vue.use(Vuex)
【发布时间】:2018-10-16 18:16:29
【问题描述】:

我有一个store.js

import Vuex from 'vuex';

export default new Vuex.Store({
  state: { customers: [] },
  mutations: {
    addCustomer (customer) {
      state.customers.push(customer);
    }
  }
});

在我的main.js 中,我指的是这样的商店,但vue-devtools 总是返回[vuex] must call Vue.use(Vuex) before creating a store instance.

import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);    
import store from './store'
new Vue({
  store,
  render: h => h(App),
}).$mount('#app');

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-component vuex


    【解决方案1】:

    您没有在 store.js 中添加以下导入:

        import Vue from 'vue';
        import Vuex from 'vuex';
    
         Vue.use(Vuex);
          export default new Vuex.Store({ ...
    

    【讨论】:

      猜你喜欢
      • 2022-01-19
      • 2021-12-08
      • 2018-04-04
      • 1970-01-01
      • 2021-03-18
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      相关资源
      最近更新 更多