This commit is contained in:
talktao 2022-09-29 15:18:10 +08:00
parent a995aff153
commit 1d8b6097ab
2 changed files with 11 additions and 10 deletions

View File

@ -30,21 +30,21 @@ class HttpRequest {
}; };
} }
interceptors(instance: AxiosInstance) { interceptors(instance: AxiosInstance) {
// 定义存放请求接口数组
let requestList = []; let requestList = [];
const setLoadingToFalse = response => { const setLoadingToFalse = response => {
requestList requestList
.filter(item => item.url == response.config.url && item.method == response.config.method) .filter(item => item.url == response.config.url && item.method == response.config.method)
.forEach(item => (item.isLoading = false)); .forEach(item => (item.isLoading = false));
//所有请求都加载完才让加载提示消失 //所有请求都加载完才让加载提示消失
if (requestList.every(item => !item.isLoading)) vuexStore.commit("changeIsLoading", false); if (requestList.every(item => !item.isLoading)) vuexStore.commit("changeIsLoading", false);
}; };
instance.interceptors.request.use( instance.interceptors.request.use(
(config: any) => { (config: any) => {
// 不用判断请求loading的路由
let ignoreLoadingUrls = ["/login"]; let ignoreLoadingUrls = ["/login"];
if (!ignoreLoadingUrls.includes(config.url)) { if (!ignoreLoadingUrls.includes(config.url)) {
@ -67,9 +67,7 @@ class HttpRequest {
return response.data; return response.data;
}, },
error => { error => {
if (error.response.status == 301) { if (error.response.status == 301) { }
vuexStore.commit("changeLoginModalVisible", true);
}
setLoadingToFalse(error); setLoadingToFalse(error);
return Promise.reject(error.response?.data); return Promise.reject(error.response?.data);
} }

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, reactive, ref, toRefs } from "vue"; import { computed, onMounted, reactive, ref, toRefs } from "vue";
import { getList } from "@/api/home"; import { getTest } from "@/api/home";
import logo from "@/assets/logo.png"; import logo from "@/assets/logo.png";
const useShowList = () => { const useShowList = () => {
@ -27,12 +27,15 @@ const useShowList = () => {
const { list } = useShowList(); const { list } = useShowList();
// //
const get = async () => { const getTestData = async () => {
const result = await getList(); let params = {
modules: "statisGradeCityDetail",
};
const result = await getTest(params);
}; };
onMounted(() => { onMounted(() => {
get(); getTestData();
}); });
</script> </script>