vue 拦截器

拦截器:请求发送之前和请求返回之后的处理

使用:1、config---dev.env.js 开发环境配置
2、 prod.env.js 生产
API:'http://www.wpdic.com'
3、在mian.js写
Vue.http.interceptors.push(function(request, next) {
if (request.url[0] === '/') {
request.url = process.env.API + request.url;
}

next(function(response) {
if (response.status == 422) {
response.body.errors.forEach(function (e) {
alertify.error(e);
});
}
});
});

原文地址:https://www.cnblogs.com/pengc/p/8734443.html