const install = (Vue, vm) => { Vue.prototype.$u.http.setConfig({ // baseUrl: 'https://yxd.ccttiot.com/prod-api', baseUrl: 'http://192.168.1.3: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 }