代码之家  ›  专栏  ›  技术社区  ›  Alexander Zeitler

vuex必须在创建存储实例之前调用Vue.use(vuex)

  •  0
  • Alexander Zeitler  · 技术社区  · 6 年前

    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');
    
    1 回复  |  直到 4 年前
        1
  •  1
  •   Boussadjra Brahim    6 年前

    您缺少在中添加以下导入 store.js :

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