You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
import { ROOTPATH as baseUrl } from "@/common/config.js"
|
|
|
|
|
|
|
|
|
|
|
|
// 这里的Vue为Vue对象(非创建出来的实例),vm为main.js中“Vue.use(httpInterceptor, app)”这一句的第二个参数,
|
|
|
|
|
|
// 为一个Vue的实例,也即每个页面的"this"
|
|
|
|
|
|
// 如果需要了解这个install方法是什么,请移步:https://uviewui.com/components/vueUse.html
|
|
|
|
|
|
const install = (Vue, vm) => {
|
|
|
|
|
|
// 此为自定义配置参数,具体参数见上方说明
|
|
|
|
|
|
Vue.prototype.$u.http.setConfig({
|
|
|
|
|
|
baseUrl,
|
|
|
|
|
|
showLoading: true, // 是否显示请求中的loading
|
|
|
|
|
|
loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
|
|
|
|
|
|
loadingText: '加载中', // 请求loading中的文字提示
|
|
|
|
|
|
loadingTime: 1000 * 60 * 3,
|
|
|
|
|
|
originalData: true, // 是否在拦截器中返回服务端的原始数据
|
|
|
|
|
|
// 设置自定义头部content-type
|
|
|
|
|
|
header: {
|
|
|
|
|
|
'content-type': 'application/json;charset=UTF-8'
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 请求拦截部分,如配置,每次请求前都会执行
|
|
|
|
|
|
Vue.prototype.$u.http.interceptor.request = (config) => {
|
|
|
|
|
|
//console.log('config-http', config)
|
|
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
// 如果return一个false值,则会取消本次请求
|
|
|
|
|
|
// if(config.url == '/user/rest') return false; // 取消某次请求
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 响应拦截,如配置,每次请求结束都会执行本方法
|
|
|
|
|
|
Vue.prototype.$u.http.interceptor.response = (res) => {
|
|
|
|
|
|
//console.log('res-http',res)
|
|
|
|
|
|
if(res.statusCode == 200){
|
|
|
|
|
|
return res
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
install
|
|
|
|
|
|
}
|