属性 'getters' 在类型 'StoreCallback' 上不存在
Property 'getters' does not exist on type 'StoreCallback'
我正在尝试在 quasar 中创建商店 space,但是当我尝试从商店访问 getter、dispatch 等时,它说它们不存在。
我的router/store/index.ts
export const storeKey: InjectionKey<VuexStore<StateInterface>> =
Symbol('vuex-key');
export default store(function (/* { ssrContext } */) {
const Store = createStore<StateInterface>({
modules: {
// example
sidebar_state,
authentication,
crud,
view,
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: !!process.env.DEBUGGING,
});
return Store;
});
和导入(在 ts 文件中而不是在 vue 文件中)
import store from './store';
let user = await store.dispatch('authentication/getUser');
错误是:
ERROR in src/router/index.ts:80:15
TS2339: Property 'getters' does not exist on type 'StoreCallback'.
78 | alert(store);
79 | let user: any;
> 80 | if (store.getters['authentication/auth']) {
| ^^^^^^^
81 | user = await store.dispatch('authentication/getUser');
82 | }
83 | if (
如您所见,文件的默认导出是一个创建新商店的函数,因此import store from './store'
是一个函数,而不是真正的商店对象。我找到了一个解决方案——单独导出 store
对象。
let Store;
export default store(function (/* { ssrContext } */) {
Store = createStore<StateInterface>({
modules: {
// example
sidebar_state,
authentication,
crud,
view,
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: !!process.env.DEBUGGING,
});
return Store;
});
export function getStore() {
return Store;
}
现在可以通过以下方式购买商店:
import { getStore } from './store';
let user = await getStore().dispatch('authentication/getUser');
** 还有一种方式(here),但是创建store时无法访问SSR Context
const Store = new Vuex.Store({...})
export { Store }
export default function (/* ssrContext */) {
return Store
}
import { Store } from './store';
let user = await Store.dispatch('authentication/getUser');
我正在尝试在 quasar 中创建商店 space,但是当我尝试从商店访问 getter、dispatch 等时,它说它们不存在。
我的router/store/index.ts
export const storeKey: InjectionKey<VuexStore<StateInterface>> =
Symbol('vuex-key');
export default store(function (/* { ssrContext } */) {
const Store = createStore<StateInterface>({
modules: {
// example
sidebar_state,
authentication,
crud,
view,
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: !!process.env.DEBUGGING,
});
return Store;
});
和导入(在 ts 文件中而不是在 vue 文件中)
import store from './store';
let user = await store.dispatch('authentication/getUser');
错误是:
ERROR in src/router/index.ts:80:15
TS2339: Property 'getters' does not exist on type 'StoreCallback'.
78 | alert(store);
79 | let user: any;
> 80 | if (store.getters['authentication/auth']) {
| ^^^^^^^
81 | user = await store.dispatch('authentication/getUser');
82 | }
83 | if (
如您所见,文件的默认导出是一个创建新商店的函数,因此import store from './store'
是一个函数,而不是真正的商店对象。我找到了一个解决方案——单独导出 store
对象。
let Store;
export default store(function (/* { ssrContext } */) {
Store = createStore<StateInterface>({
modules: {
// example
sidebar_state,
authentication,
crud,
view,
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: !!process.env.DEBUGGING,
});
return Store;
});
export function getStore() {
return Store;
}
现在可以通过以下方式购买商店:
import { getStore } from './store';
let user = await getStore().dispatch('authentication/getUser');
** 还有一种方式(here),但是创建store时无法访问SSR Context
const Store = new Vuex.Store({...})
export { Store }
export default function (/* ssrContext */) {
return Store
}
import { Store } from './store';
let user = await Store.dispatch('authentication/getUser');