다른 작업 내에서 작업 호출

내 작업에 대해 다음과 같은 설정이 있습니다.

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

내가 전화를 할 수 있도록하려면이 예에서는 너무 다른 내에서 하나의 액션을 호출 할 수 있도록하려는 get2()내에서 get1(). 가능합니까? 그렇다면 어떻게해야합니까?



답변

dispatch첫 번째 매개 변수에 전달 된 객체 의 메소드에 액세스 할 수 있습니다 .

get1: ({ commit, dispatch }) => {
  dispatch('get2');
},

이것은 문서 에서 다룹니다 .


답변

페이로드가 필요하지 않은 작업

actions: {
    BEFORE: async (context, payload) => {
    },
    AFTER: async (context, payload) => {
        await context.dispatch('BEFORE');
    }
}

페이로드 가 필요한 작업

actions: {
    BEFORE: async (context, payload) => {
    },
    AFTER: async (context, payload) => {
        var payload = {}//prepare payload
        await context.dispatch('BEFORE', payload);
    }
}

답변

export actions = {
  GET_DATA (context) {
     // do stuff
     context.dispatch('GET_MORE_DATA');
  },

  GET_MORE_DATA (context) {
    // do more stuff
  }
}

답변