我不明白为什么会出现此错误。一切看起来都正常。 像这样将商店导入组件。
import store from './store';
new Vue({
components: {
SomeComponent
},
store
});
我的店是这样的
import Vue from 'vue';
import Vuex from 'vuex';
import * as getters from './getters';
import * as actions from './actions';
import mutations from './mutations';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
something
}
})
请帮忙。 谢谢
Uncaught Error: [vuex] must call Vue.use(Vuex) before creating a store instance.
最佳答案
使用 Vue CLI 并像这样设置对我有用
在商店/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
something: ['something']
}
})
在 main.js 中 从“vue”导入 Vue
import App from './App'
import router from './router'
import store from './store'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})
关于javascript - 在创建商店实例之前必须调用 Vue.use(Vuex),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44843449/