[英]How to export module in Vuex
I would like to export Vuex module like below: 我想像下面那样导出Vuex模块:
export {
state,
mutations,
actions,
getters
}
but when I am trying to include it in my index file it throws error. 但是,当我尝试将其包含在索引文件中时,会引发错误。 Something with types incompatibility.
类型不兼容的东西。 I think I should specify type of above object but I do not know what type it is.
我想我应该指定上述对象的类型,但我不知道它是什么类型。
import * as itemsModule from './app/store/items/module'
let store = new Vuex.Store({
modules: {
items: itemsModule
}
});
throws: 抛出:
is not assignable to parameter of type 'StoreOptions<{}>'.
不可分配给“ StoreOptions <{}>”类型的参数。 Types of property 'modules' are incompatible.
属性“模块”的类型不兼容。
Regards 问候
The way you are importing and exporting is not correct. 您导入和导出的方式不正确。 Try it that way:
尝试这种方式:
module.js module.js
export default {
state,
mutations,
actions,
getters
}
store.js store.js
import itemsModule from './app/store/items/module'
explanation: the way you were importing the module, you got this kind of object: 说明:在导入模块的方式中,您得到了这种对象:
{
default: {
actions: {/** ... */}
getters: {/** ... */}
mutations: {/** ... */}
state: {/** ... */}
}
}
which is not the structure the store is expecting for a module. 这不是商店期望模块的结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.