From 9e147a5a1fe03de1a4bdf8d2b0f2793e78ee0db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=9F=E8=B1=86=E5=93=A5?= Date: Sun, 31 Jul 2022 08:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E5=A2=9E=E5=8A=A0to?= =?UTF-8?q?ken=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- src/utils/request.ts | 8 +++++--- vite.config.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d6c413a..60bb23d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "type": "pwa-chrome", "request": "launch", "name": "Launch Chrome against localhost", - "url": "http://localhost:3000", + "url": "http://localhost:3001", "webRoot": "${workspaceFolder}" } ] diff --git a/src/utils/request.ts b/src/utils/request.ts index 2bc3d41..8eba8f5 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,6 +1,7 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios' import { toTuofeng } from './index' -import { Page } from '../types/page' +import { Page } from '@/types/page' +import { useLoginStore } from '@/store/modules/login' export interface QuickResponseData { status: number @@ -21,9 +22,10 @@ const quickRequest: AxiosInstance = axios.create({ // 请求拦截器 quickRequest.interceptors.request.use( (config) => { + const loginStore = useLoginStore() console.log('request', config) - // const token = '' - // config.headers.token = `Bearer ${token}` + const token = loginStore.getToken + config.headers.authorization = `Bearer ${token}` return config }, (error) => { diff --git a/vite.config.ts b/vite.config.ts index 366c87b..e864dcd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -47,8 +47,8 @@ export default ({ command, mode }) => { port: VITE_PORT, proxy: { [VITE_APP_BASE_URL]: { - // target: 'http://localhost:3002/', // 代理的目标地址 - target: 'http://110.42.130.88:3102/', // 代理的目标地址 + // target: 'http://localhost:3002/', // 代理的目标地址-本地 + target: 'http://110.42.130.88:3102/', // 代理的目标地址-线上 changeOrigin: false, // 开发模式,默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址 secure: false, // 是否https接口 ws: false, // 是否代理websockets -- Gitee