itsource

vuex 작업 반환의 메서드가 정의되지 않았습니다.

mycopycode 2022. 7. 21. 23:40
반응형

vuex 작업 반환의 메서드가 정의되지 않았습니다.

Vuex 액션에는 다음과 같은 방법이 있습니다.

const actions = {
  async fetchByQuery({ commit, title }) {
    console.log(title);
    //other codes
  },
};
And method to reach to vuex action:

  methods: {
     ...mapActions(["fetchByQuery"]),
    getData(title) {
        console.log("teacher");
      this.fetchByQuery(title);
    }
  }

단, 액션의 console.log()에 의해undefined출력을 표시합니다.

내가 뭘 놓쳤지?

동작에 포함된 매개 변수를 잘못 알고 있습니다.

({ commit, title })그래야만 한다.({ commit }, title)

그렇지 않으면 속성 제목을 가진 개체로 호출해야 합니다.

Vuex 작업에는 컨텍스트 개체라는 두 가지 매개 변수가 필요합니다.{ commit }및 payload(title(고객님의 경우)

액션 선언을 다음과 같이 변경합니다.

const actions = {
  async fetchByQuery({ commit }, title) {
    console.log(title);
    //other codes
  },
};

언급URL : https://stackoverflow.com/questions/62889396/method-in-vuex-action-return-undefined

반응형