Sprinkler-app/common/http.interceptor.js
2026-03-26 17:48:21 +08:00

35 lines
1.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const install = (Vue, vm) => {
Vue.prototype.$u.http.setConfig({
baseUrl: 'https://yxd.ccttiot.com/prod-api',
// baseUrl: 'http://192.168.1.5:8081',
loadingText: '',
loadingTime: 800,
// 设置自定义头部content-type
header: {
'content-type': 'application/json;charset=UTF-8',
},
// ......
});
// 请求拦截部分,如配置,每次请求前都会执行
Vue.prototype.$u.http.interceptor.request = (config) => {
const token = uni.getStorageSync('token');
config.header.Authorization = token;
// config.header.Tenant-Id=1
// #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
}