From 43195af76e05322c5992d2a0799a9d28fba3425b Mon Sep 17 00:00:00 2001 From: zch Date: Wed, 27 May 2026 10:24:44 +0800 Subject: [PATCH] =?UTF-8?q?change(request):=20=E4=BB=85=E5=9C=A8=E6=9C=89?= =?UTF-8?q?=E6=95=88=20token=20=E6=97=B6=E6=B3=A8=E5=85=A5=20Authorization?= =?UTF-8?q?=20=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/request.js | 7 ++++++- vue.config.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/utils/request.js b/src/utils/request.js index e92bb22..99dbe5c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -17,7 +17,12 @@ service.interceptors.response.use((res) => { return res.data; }); service.interceptors.request.use(config => { - config.headers['Authorization'] = 'Bearer ' + getToken() + // 仅在存在有效 token 时才注入 Authorization 头,避免匿名请求时字面量 "Bearer undefined" 导致后端 JWT 解析噪音 + const token = getToken() + if (token) { + config.headers['Authorization'] = 'Bearer ' + token + } + return config }, error => { }) diff --git a/vue.config.js b/vue.config.js index 1190f01..bf4ae9b 100644 --- a/vue.config.js +++ b/vue.config.js @@ -9,6 +9,7 @@ module.exports = defineConfig({ // target: `http://175.27.215.92:8899/prod-api`, // target: `http://192.168.137.1:9081`, target: `http://1.13.177.47:6699/prod-api`, + // target: `http://localhost:6698`, // target: `http://192.168.100.100:9081`, changeOrigin: true, pathRewrite: { ["^" + '/prod-api']: "",