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.
|
|
const install = (Vue, vm) => { // 请求地址
let baseUrl = vm.API.PRODURL; if(vm.API.DEV == 'dev'){ baseUrl = vm.API.DEVURL; }; // 请求全局配置
Vue.prototype.$u.http.setConfig({ baseUrl: baseUrl, method: 'POST', dataType: 'json', // 返回数据时自动 JSON.parse()
showLoading: true, // 是否显示请求中的loading
loadingText: '正在加载', loadingTime: 800 // 延迟800毫秒时显示加载框
}); // 请求前拦截
Vue.prototype.$u.http.interceptor.request = config => { // console.log("config", config, config.url)
let release_apis = [ '/api/supplier/login', '/api/canteen/login' ]; if(!config.header.token && !release_apis.includes(config.url)){ return false; // 拦截,拦截没有token的页面,但不包括登录页的api
}else{ return true; // 放行
} }; // 响应拦截
Vue.prototype.$u.http.interceptor.response = res => { if(res.code == 0) { return res; } else { vm.$msg(res.msg); return false; } }}
export default { install}
|