Vite跨域设置
步骤一 vite.config.ts配置
proxy: {// 跨域代理
'/apis': {
// target: 'http://' + env.VUE_APP_BASE_API,
target: 'http://url:port', //
changeOrigin: true,
rewrite: (path) => path.replace(/^\/apis/, '')
},
// 代理 WebSocket 或 socket
// '/socket.io': {
// target: 'ws://localhost:3000',
// ws: true
// }
},
步骤二 axios在封装
baseURL要改为代理的本地地址 /apis
baseURL:"/apis",// 跨域代理