我得到了 vujes typescript 项目,在 vuex 商店我得到了类似的东西:
async getUserProfile ({ dispatch, commit }: any) {}
好吧我不想要
any
因为那很糟糕,而且您在编辑器中没有帮助/自动完成功能。我找到了 import { Dispatch, Commit } from "vuex";
但是如何将该信息传递给 { dispatch, commit }: any
最佳答案
您使用 ActionContext<S, R>
,就像 Vuex 一样:
getUserProfile( context: ActionContext<S, R>) {}
在哪里
S
是 State
和 R
是 RootState
.然后您调用
dispatch
和 commit
脱离上下文: context.dispatch('action')
context.commit('mutation')
关于javascript - vuex 中 { dispatch, commit } 的类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50375281/