Skip to content

Commit

Permalink
refactor: loginApi直接返回axios规避vue-request非setup警告
Browse files Browse the repository at this point in the history
  • Loading branch information
yuntian001 committed Dec 20, 2022
1 parent 2fe9f33 commit eb036b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ export class LoginParams {
export interface LoginResult {
token: string;
}
export function loginApi() {
return request<LoginResult, [LoginParams]>((params) => ({
url: Api.LOGIN,
method: 'post',
data: params,
}));
export function loginApi<T extends boolean = true>(returnAxios: T = true as T) {
return request<LoginResult, [LoginParams], T>(
(params) => ({
url: Api.LOGIN,
method: 'post',
data: params,
}),
{},
returnAxios,
);
}

// 获取用户详细信息
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineStore({
// 登录
login: async function (params: LoginParams) {
mitter.emit(event.BEFORE_LOGIN);
const res = await loginApi().runAsync(params);
const res = await loginApi()(params);
await this.init(res.token);
mitter.emit(event.AFTER_LOGIN);
},
Expand Down

0 comments on commit eb036b6

Please sign in to comment.