【发布时间】:2019-12-19 09:51:36
【问题描述】:
/src/middlewares/auth.ts 文件:
import store from '@/store'
export default {
guest(): void {
if (store.state.auth.authenticated === false) {
// do some action
}
}
}
/src/store.ts 文件:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
auth
}
})
/src/store/auth.ts:
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
@Module
export default class Auth extends VuexModule {
public authenticated: boolean = false
}
但是我收到 TS 错误:Object is of type 'unknown'
然后我的npm run build 失败了。我怎样才能输入store 这样这个错误就会消失?
更新 1
问题出在:if (store.state.auth.authenticated === false)
更新 2
这三个文件的目录结构:
- /src/middlewares/auth.ts
- /src/store.ts
- /src/store/auth.ts
更新 3
如果我将 store.state.auth.authenticated 更改为 store.state 然后编译器停止抱怨,我认为它与我的商店 auth.ts 文件有关,我需要以某种方式输入定义。
【问题讨论】:
-
您能否提供更多上下文并指出错误所在的行?没有足够的代码来重现错误。
-
@tony19 更新了我的问题。
-
你的目录/文件结构是什么样的,至少对于这两个文件来说是这样的?
-
@Phil,我正在使用 vuex-module-decorators。
标签: javascript typescript vue.js vuex