码迷,mamicode.com
首页 > 其他好文 > 详细

vue2

时间:2017-04-05 17:40:30      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:ret   int   url   http   body   bsp   amp   turn   pre   

vue2自带的拦截器,已被 axios 替代: https://github.com/mzabriskie/axios

try {
  Vue.http.interceptors.push(function (request, next) {
    // ...
    // 请求发送前的处理逻辑
    // ...

    var getFullUrl = function (url) {
      if (url.slice(0, 2) == "//") return url;

      if (url[0] != "/") {
        url = "/" + url;
      }
      return "//172.30.8.132:808" + url;
    }

    // request.method = "JSONP";
    request.url = getFullUrl(request.url);

    next(function (response) {
      if (response.status == 200) {
        if (response.body && response.body.msg) {
          this.$message.error(response.body.msg);
          return new Promise(function (resolve, reject) {
            reject(response);
          });
        }
      }
      else if (response.status == 500) {
        this.$message.error(response.body);
        // throw new Error("Error");
        return new Promise(function (resolve, reject) {
          reject(response);
        });
      }
      return;
    })
  });
} catch (e) {
  //console.info("Vue.http.interceptors:" + e.message);
}

 

vue2

标签:ret   int   url   http   body   bsp   amp   turn   pre   

原文地址:http://www.cnblogs.com/newsea/p/6669589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!