从另一个动作中调用一个动作 [英] Call an action from within another action

查看:25
本文介绍了从另一个动作中调用一个动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作有以下设置:

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');
},

这在文档中有介绍.

这篇关于从另一个动作中调用一个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆