Sprinkler-app/common/http.interceptor.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-12-05 16:45:28 +08:00
const install = (Vue, vm) => {
2024-03-13 10:54:22 +08:00
Vue.prototype.$u.http.setConfig({
2026-02-25 18:01:42 +08:00
baseUrl: 'https://yxd.ccttiot.com/prod-api',
// baseUrl: 'http://192.168.1.4:8081',
2024-03-13 10:54:22 +08:00
loadingText: '努力加载中~',
loadingTime: 800,
// 设置自定义头部content-type
header: {
'content-type': 'application/json;charset=UTF-8',
},
// ......
});
2023-12-05 16:45:28 +08:00
// 请求拦截部分,如配置,每次请求前都会执行
Vue.prototype.$u.http.interceptor.request = (config) => {
2024-03-13 10:54:22 +08:00
const token = uni.getStorageSync('token');
2023-12-05 16:45:28 +08:00
config.header.Authorization = token;
2023-12-06 10:06:54 +08:00
// config.header.Tenant-Id=1
2023-12-05 16:45:28 +08:00
// #ifdef H5
config.header.Authorization = 'Bearer '+token;
// #endif
// 可以对某个url进行特别处理此url参数为this.$u.get(url)中的url值
if(config.url == '/user/login') config.header.noToken = true;
// 最后需要将config进行return
return config;
}
// 响应拦截,如配置,每次请求结束都会执行本方法
Vue.prototype.$u.http.interceptor.response = (res) => {
return res;
}
}
export default {
install
}