IPPSWAP-h5
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.
 
 
 
 

57 lines
1.3 KiB

import Vue from 'vue'
import axios from 'axios'
import "./uniapp-axios-adapter"
import {withRepeatGuard} from "./with-repeat-guard";
import {tansParams} from "../utils/atom";
import {withAuthentication} from "./with-authentication";
import Constant from "../utils/constant";
const service = axios.create({
withCredentials: false, //表示跨域请求时是否需要使用凭证
crossDomain: true,
baseURL: Constant.baseUrl,
timeout: 160000
})
// withAuthentication(service)
withRepeatGuard(service)
/**
* 请求拦截
*
* 除 Axios 默认配置, 还接受以下配置
* $withCredentials: 是否携带 token, 默认为 true
* $withLoading: 是否显示 loading, 默认 true
* $withRepeatGuard: 是否开启重复请求拦截, 默认 true
*/
service.interceptors.request.use(
config => {
uni.showLoading({
title: 'loading',
mask: true
})
// get请求映射params参数
if (config.method === 'get' && config.params) {
let url = config.url + '?' + tansParams(config.params);
url = url.slice(0, -1);
config.params = {};
config.url = url;
}
return config;
},
);
service.interceptors.response.use(
response => {
uni.hideLoading();
return response;
},
error => {
uni.hideLoading();
return Promise.reject(error);
},
)
export default service