Skip to content

sl1673495/vuex-error-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

vuex全局错误处理插件

const handleError = (err) => {
  // 处理错误
  if (err.code === 401) {
    notify({
      content: '请先登录。'
    })
  }
}
const store = new Vuex.Store({
    state,
    mutations,
    getters,
    actions,
    plugins: [errorPlugin({
      onActionError: (e) => {
        handleError(e)
      }
    })]
  })
}

注意点

action支持两种风格 如果用普通的promise 需要把promise return出去 如果用async函数则不需要

fetchTodos ({commit}) {
    return model.getAllTodos().then(data => {
      commit('fillTodos', data)
    })
  }
// 或
async fetchTodos ({commit}) {
    const data = await model.getAllTodos()
    commit('fillTodos', data)
  }  

About

提供vuex全局拦截错误统一处理能力。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published