programing

내부에 변이가 없는 Action vuex를 호출하는 것이 나쁜가요?

itsource 2022. 7. 3. 23:36
반응형

내부에 변이가 없는 Action vuex를 호출하는 것이 나쁜가요?

Vuex와 관련된 API를 모두 이동하려고 하는데, 액션을 호출한 후 실제로 아무것도 변환하지 않아도 되는 경우가 있습니다.괜찮으시다면 베스트 프랙티스는 무엇입니까?

actions: {
  save (context, payload) {
    axios.post(`http://jsonplaceholder.typicode.com/posts`, {body: payload})
  }
}

API에 정보를 게시하고 상태를 변경하지 않으면 거의 괜찮다고 말할 수 있습니다.

단, 상태를 변경하지 않을 경우 API 포스트가 작동했는지 실패했는지 사용자에게 알리는 어플리케이션의 콘텐츠는 어떻게 변경됩니까?

가장 좋은 방법은 공리적인 약속에 따라 국가를 변형시키는 것이다.resolve또는fail

actions: {
  save (context, payload) {
    axios.post(`http://jsonplaceholder.typicode.com/posts`, {body: payload})
        .then(data => /*change state to let the user that it succeed*/)
        .catch(err => /*set a state variable that contains an error message*/);
  }
}

언급URL : https://stackoverflow.com/questions/58606858/is-it-bad-calling-action-vuex-without-mutation-inside-it

반응형