对于axios请求做的其他操作,例如拦截、过滤等等·····
下图中baseUri自己定义所需的baseURL即可
import axios from "axios";
import {baseUri} from "./api.js"
const service = axios.create({
baseURL: baseUri,
timeout: 600000,
});
axios.defaults.retry = 4;
axios.defaults.retryDelay = 4000;
axios.defaults.withCredentials = true;
function startLoading() {
console.log(baseUri);
uni.showLoading({
title: "加载中..."
});
}
function endLoading() {
uni.hideLoading();
}
let needLoadingRequestCount = 0
export function showFullScreenLoading() {
if (needLoadingRequestCount === 0) {
startLoading()
}
needLoadingRequestCount++
}
export function tryHideFullScreenLoading() {
if (needLoadingRequestCount <= 0)
return needLoadingRequestCount--;
if (needLoadingRequestCount === 0) {
endLoading()
}
}
service.interceptors.request.use((config) => {
showFullScreenLoading();
return config;
}, error => {
tryHideFullScreenLoading();
return Promise.reject(error)
});
service.interceptors.response.use(
function(response) {
tryHideFullScreenLoading();
return response;
}
);
export default service;
可以
虽然还没看懂,还是要努力学习
默默的点赞路过
哇哦