Explorar o código

Auto merge base into tabbar

GitHub Actions hai 1 ano
pai
achega
7f80ded4c2
Modificáronse 3 ficheiros con 24 adicións e 3 borrados
  1. 1 1
      package.json
  2. 13 1
      src/service/index/foo.ts
  3. 10 1
      src/utils/http.ts

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "name": "unibest",
   "type": "commonjs",
-  "version": "2.5.5",
+  "version": "2.6.3",
   "description": "unibest - 最好的 uniapp 开发模板",
   "author": {
     "name": "feige996",

+ 13 - 1
src/service/index/foo.ts

@@ -8,8 +8,20 @@ export interface IFooItem {
 export const getFooAPI = (name: string) => {
   return http.get<IFooItem>('/foo', { name })
 }
+/** GET 请求;支持 传递 header 的范例 */
+export const getFooAPI2 = (name: string) => {
+  return http.get<IFooItem>('/foo', { name }, { 'Content-Type-100': '100' })
+}
 
 /** POST 请求 */
 export const postFooAPI = (name: string) => {
-  return http.post<IFooItem>('/foo', { name }, { name })
+  return http.post<IFooItem>('/foo', { name })
+}
+/** POST 请求;需要传递 query 参数的范例;微信小程序经常有同时需要query参数和body参数的场景 */
+export const postFooAPI2 = (name: string) => {
+  return http.post<IFooItem>('/foo', { name })
+}
+/** POST 请求;支持 传递 header 的范例 */
+export const postFooAPI3 = (name: string) => {
+  return http.post<IFooItem>('/foo', { name }, { name }, { 'Content-Type-100': '100' })
 }

+ 10 - 1
src/utils/http.ts

@@ -46,13 +46,19 @@ export const http = <T>(options: CustomRequestOptions) => {
  * GET 请求
  * @param url 后台地址
  * @param query 请求query参数
+ * @param header 请求头,默认为json格式
  * @returns
  */
-export const httpGet = <T>(url: string, query?: Record<string, any>) => {
+export const httpGet = <T>(
+  url: string,
+  query?: Record<string, any>,
+  header?: Record<string, any>,
+) => {
   return http<T>({
     url,
     query,
     method: 'GET',
+    header,
   })
 }
 
@@ -61,18 +67,21 @@ export const httpGet = <T>(url: string, query?: Record<string, any>) => {
  * @param url 后台地址
  * @param data 请求body参数
  * @param query 请求query参数,post请求也支持query,很多微信接口都需要
+ * @param header 请求头,默认为json格式
  * @returns
  */
 export const httpPost = <T>(
   url: string,
   data?: Record<string, any>,
   query?: Record<string, any>,
+  header?: Record<string, any>,
 ) => {
   return http<T>({
     url,
     query,
     data,
     method: 'POST',
+    header,
   })
 }