【发布时间】:2018-09-25 10:09:51
【问题描述】:
我正在尝试为我的 Vue.js(Nuxt) 项目编写一个简单的插件。我遇到了这个帖子Adding Mutations to Vuex store as part of Vue Plugin,但仍然无法正常工作。
这是我的应用程序结构。
~ is root
~/plugins/HTTP/index.js
~/plugins/HTTP/_store/ => index.js, actions.js, getters.js, mutations.js
~/plugins/HTTP/_api/ => index.js
**Global Store**
~/store/index.js
~/store/modules/
~/store/modules/testing => index.js, actions.js, getters.js, mutations.js
在我的~/plugins/HTTP/index.js 中,我有以下代码
import Vue from 'vue';
import store from '~/store';
const HTTP = {
install(vue, { store }){ // Now you plugin depend on store
if(!store){
throw new Error('Please provide vuex plugin.')
}
// register your own vuex module
store.registerModule({store})
}
}
export default HTTP;
Vue.use(HTTP)
在我的~/store/index.js 我有以下代码:
import Vuex from 'vuex'
import testingModule from './modules/testing'
const state = () => {
return new Vuex.Store({
modules:{
testing: testingModule
}
})
}
export default state
当我尝试运行它时,它给了我以下消息:
Cannot destructure property `store` of 'undefined' or 'null'.
我在这里做错了什么?
【问题讨论】: