Vue.js: Nuxt error handling

前端 未结 4 1194
面向向阳花
面向向阳花 2021-02-05 00:33

Struggling a bit to set up error handling with vuex. There seems to be quite a few ways to do so and little documentation on proper error handling. I\'ve been experimenting with

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 01:03

    Use Promise in action

    Example in vuex:

    NEW_AUTH({ commit }) {
        return new Promise((resolve, reject) => {
          this.$axios.$get('/token').then((res) => {
            ...
            resolve();
          }).catch((error) => {
            reject(error);
          })
        })
      }
    

    In page:

    this.$store.dispatch('NEW_AUTH')
       .then(() => ... )
       .catch((error) => ... )
    

提交回复
热议问题