我得到了vujes typescript项目,在vuexstore 我得到了类似的东西:
async getUserProfile ({ dispatch, commit }: any) {}
我不想要any
,因为这很糟糕,而且你在编辑器中没有帮助/自动完成.我找到了import { Dispatch, Commit } from "vuex";
,但是如何把信息传给{ dispatch, commit }: any
呢
我得到了vujes typescript项目,在vuexstore 我得到了类似的东西:
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')