Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

javascript - vuex中的{dispatch,commit}的类型是什么?(What are the types for { dispatch, commit } in vuex?)

I got vujes typescript project and in vuex store i got something like:(我得到了vujes打字稿项目,在vuex商店中,我得到了类似的东西:)

async getUserProfile ({ dispatch, commit }: any) {} Well i dont want any because that suck and you dont have help/autocomplete in editor.(好吧,我不需要any因为那很烂,您在编辑器中没有帮助/自动完成功能。) I found this import { Dispatch, Commit } from "vuex";(我import { Dispatch, Commit } from "vuex";找到了此import { Dispatch, Commit } from "vuex";) but how to pass that info to { dispatch, commit }: any(但是如何将该信息传递给{ dispatch, commit }: any)   ask by pregmatch translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't destructure it, instead you use ActionContext<S, R> , like Vuex does:(您无需对其进行解构,而是使用ActionContext<S, R> ,就像Vuex那样:)

getUserProfile( context: ActionContext<S, R>) {} Where S is the State and R is the RootState .(其中SStateRRootState 。) Then you call dispatch and commit off of the context:(然后调用dispatch并从上下文中commit :) context.dispatch('action') context.commit('mutation')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...