vite2.0+vue3 配置本地服务器代理
vite.config.ts文件中添加
- server:{
open:false,
proxy: {
// 选项写法
'/api': {
target: 'http://localhost:12344/api/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
http.ts 请求拦截器中添加
- const ctx = '/api'
- '/api' 是vite.config.ts中配置 proxy里的 '/api'项
然后配置baseURl = ctx