Skip to content

Commit

Permalink
fix: 修复请求loading异常和mock异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Oct 19, 2022
1 parent b928655 commit 11afdc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { closeLoading, loading } from '@/utils/loading';
import { useUserStore } from '@/store';
import axios, { AxiosRequestConfig } from 'axios';
import { ElMessage } from 'element-plus';
import log from './log';
import { useRequest, Options, setGlobalOptions } from 'vue-request';
import { globalLoading } from './loading';

const service = axios.create({
baseURL: '/', // url = base url + request url
Expand Down Expand Up @@ -78,7 +78,7 @@ function request<R, P extends unknown[] = [], T = boolean>(
) {
const axiosService = async (...args: P): Promise<R> => {
try {
!options?.noLoading && globalLoading.loading();
!options?.noLoading && loading();
const { data: res } = await service(await axiosConfig(...args));
if (!res || res.code === undefined) {
throw Error('返回值解析失败');
Expand All @@ -94,10 +94,10 @@ function request<R, P extends unknown[] = [], T = boolean>(
if (options?.success) {
ElMessage.success({ message: res.msg });
}
!options?.noLoading && globalLoading.close();
!options?.noLoading && closeLoading();
return options?.needAll ? res : res.data;
} catch (e) {
!options?.noLoading && globalLoading.close();
!options?.noLoading && closeLoading();
!options?.noError &&
ElMessage.error({
message: e instanceof Error ? e.message : String(e),
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default ({ command, mode }: ConfigEnv): UserConfigExport => {
// include: ['./src/**/lang/**/*.json', './src/**/lang/*.json'],
// }),
viteMockServe({
mockPath: pathResolve('mock/apiDemo'),
mockPath: 'mock/apiDemo',
localEnabled: command === 'serve',
prodEnabled: command !== 'serve',
// 这样可以控制关闭mock的时候不让mock打包到最终代码内
Expand Down

0 comments on commit 11afdc4

Please sign in to comment.