Call an action from within another action

后端 未结 5 712
一个人的身影
一个人的身影 2021-01-30 05:03

I have the following setup for my actions:

get1: ({commit}) => {
  //things
  this.get2(); //this is my question!
},
get         


        
5条回答
  •  有刺的猬
    2021-01-30 05:11

    You can access the dispatch method through the first argument (context):

    export const actions = {
      get({ commit, dispatch }) {
        dispatch('action2')
      }
    }

    However, if you use namespaced you need to specify an option:

    export const actions = {
      get({ commit, dispatch }) {
        dispatch('action2', {}, { root: true })
      }
    }

提交回复
热议问题