javascript - axios 如何統一處理同類型錯誤?
巴扎黑
巴扎黑 2017-05-19 10:10:54
0
1
462
// interceptors
axios.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
    // 处理统一的验证失效错误.
    return Promise.reject(error);
  });

// 页面中
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  }, function (err) {
    // 在此处处理特定业务错误: 
    console.log(err.msg)
    // 问题是: 当我在拦截器里处理了验证失效后, 它还是会执行到这里面
  })

我的問題是: 我在攔截器裡處理完驗證錯誤之後, 如何不讓頁面中單獨的業務處理執行 ?

巴扎黑
巴扎黑

全部回覆(1)
曾经蜡笔没有小新

業務邏輯應該在 then()裡面吧?
err 裡面處理錯誤

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!