从另一个动作中调用一个动作
问题描述:
我的操作有以下设置:
get1: ({commit}) => {
//things
this.get2(); //this is my question!
},
get2: ({commit}) => {
//things
},
我希望能够从另一个内部调用一个操作,因此在本示例中,我希望能够从 get1()
内部调用 get2()
.这可能吗,如果可以,我该怎么做?
I want to be able to call one action from within another, so in this example I want to be able to call get2()
from within get1()
. Is this possible, and if so, how can I do it?
答
您可以访问第一个参数中传递的对象中的 dispatch
方法:
You have access to the dispatch
method in the object passed in the first parameter:
get1: ({ commit, dispatch }) => {
dispatch('get2');
},
这在文档中有介绍.