Vue.http.interceptors.push((request, next) => {
console.log(this)//此处this为请求所在页面的Vue实例
// modify request
request.method = 'POST';//在请求之前可以进行一些预处理和配置
// continue to next interceptor
next((response) => {//在响应之后传给then之前对response进行修改和逻辑判断。对于token时候已过期的判断,就添加在此处,页面中任何一次http请求都会先调用此处方法
response.body = '...';
return response;
});
});
// ajax.js
function plugin(Vue){
Object.defineProperties(Vue.prototype,{
$$http:{
get(){
return option(Vue);
}
}
})
}
function option(Vue){
let v = new Vue();
return {
get(a,b){
let promise = new Promise(function(reslove,reject){
v.$http.get(a,b).then((res)=>{
reslove(res)
},(err)=>{
//处理token过期问题。
})
})
return promise;
}
}
}
module.exports=plugin;
//main.js
import ajax from './ajax.js'
Vue.use(ajax)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有