Skip to content

Commit

Permalink
feat: 🚀 新增请求示例,参见 loginApi
Browse files Browse the repository at this point in the history
  • Loading branch information
Halsey committed Jul 14, 2022
1 parent a86e408 commit d49b227
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RequestHttp {
const globalStore = GlobalStore();
// * 将当前请求添加到 pending 中
axiosCanceler.addPending(config);
// * 如果当前请求不需要显示 loading,在api服务中通过指定的第三个参数: { headers: { noLoading: true } }来控制不显示loading,参见loginApi
// * 如果当前请求不需要显示 loading,在 api 服务中通过指定的第三个参数: { headers: { noLoading: true } }来控制不显示loading,参见loginApi
config.headers!.noLoading || showFullScreenLoading();
const token: string = globalStore.token;
return { ...config, headers: { ...config.headers, "x-access-token": token } };
Expand Down
7 changes: 5 additions & 2 deletions src/api/modules/login.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Login } from "@/api/interface/index";
import { PORT1 } from "@/api/config/servicePort";
import qs from "qs";

import http from "@/api";

Expand All @@ -8,8 +9,10 @@ import http from "@/api";
*/
// * 用户登录接口
export const loginApi = (params: Login.ReqLoginForm) => {
// return http.post<Login.ResLogin>(PORT1 + `/login`, params, { headers: { noLoading: true } });
return http.post<Login.ResLogin>(PORT1 + `/login`, params);
return http.post<Login.ResLogin>(PORT1 + `/login`, params); // 正常 post json 请求 ==> application/json
return http.post<Login.ResLogin>(PORT1 + `/login`, {}, { params }); // post 请求携带 query 参数 ==> ?username=admin&password=123456
return http.post<Login.ResLogin>(PORT1 + `/login`, qs.stringify(params)); // post 请求携带 表单 参数 ==> application/x-www-form-urlencoded
return http.post<Login.ResLogin>(PORT1 + `/login`, params, { headers: { noLoading: true } }); // 控制当前请求不显示 loading
};

// * 获取按钮权限
Expand Down

1 comment on commit d49b227

@vercel
Copy link

@vercel vercel bot commented on d49b227 Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.