From 39fa3f91374019d7349159fef79636cf1fad5439 Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Sat, 7 Jan 2023 10:07:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=B7=E6=B1=82=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=95=B0=E7=BB=84query=20=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 ++ src/api/example.ts | 1 + src/utils/request.ts | 2 ++ src/views/example/request.vue | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cebba4b4..d8b9a436 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "nprogress": "^0.2.0", "path-browserify": "^1.0.1", "pinia": "^2.0.14", + "qs": "^6.11.0", "vue": "^3.2.25", "vue-i18n": "^9.1.10", "vue-request": "^2.0.0-rc.2", @@ -56,6 +57,7 @@ "@types/node": "^18.0.1", "@types/nprogress": "^0.2.0", "@types/path-browserify": "^1.0.0", + "@types/qs": "^6.9.7", "@typescript-eslint/eslint-plugin": "^5.33.1", "@typescript-eslint/parser": "^5.33.1", "@vitejs/plugin-vue": "^4.0.0", diff --git a/src/api/example.ts b/src/api/example.ts index f31ae5ef..ca90793e 100644 --- a/src/api/example.ts +++ b/src/api/example.ts @@ -8,6 +8,7 @@ const enum Api { export interface ListParams { page: number; size: number; + createTime?: [string, string]; } export interface ListResult { total: number; diff --git a/src/utils/request.ts b/src/utils/request.ts index fb4a0752..2a713b64 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -4,10 +4,12 @@ import axios, { AxiosRequestConfig } from 'axios'; import { ElMessage } from 'element-plus'; import log from './log'; import { useRequest, Options, setGlobalOptions } from 'vue-request'; +import qs from 'qs'; const t = (...args: [string | number]) => useGlobalStore().i18n.t(...args); const service = axios.create({ baseURL: '/api/', // url = base url + request url timeout: 10000, // request timeout + paramsSerializer: (params) => qs.stringify(params, { arrayFormat: 'repeat' }), // 数组query参数转换为repeat a=1&a=2 }); // 请求拦截器 service.interceptors.request.use( diff --git a/src/views/example/request.vue b/src/views/example/request.vue index ca5e8f66..52070474 100644 --- a/src/views/example/request.vue +++ b/src/views/example/request.vue @@ -1,7 +1,7 @@