单独封装到js文件里面在main.js里面引用如下
import httpInterceptor from '@/common/request.js'
Vue.use(httpInterceptor, app)
js文件里面实例如下
const install = (Vue, vm) => {
Vue.prototype.$u.http.setConfig({
baseUrl: '',
loadingText: '请求中...',
loadingTime: 800,
originalData: true,
loadingMask: true,
// 设置自定义头部content-type
});
Vue.prototype.$u.http.interceptor.request = (config) => {
uni.$u.warnning(config);
return config;
}
Vue.prototype.$u.http.interceptor.response = (response) => {
uni.$u.warnning("------------打印响应拦截------------");
uni.$u.warnning(response);
return response;
}
}
export default {
install
}