fix: 配置Vite代理解决跨域问题,并对接真实API接口

This commit is contained in:
2025-11-25 11:52:05 +08:00
parent 51ba89192e
commit b841481243
3 changed files with 53 additions and 39 deletions

View File

@@ -4,4 +4,18 @@ import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
// 只要你请求以 /api 开头,就会被转发到目标服务器
'/api': {
target: 'http://192.168.1.254:9001',
changeOrigin: true,
// 如果后端路径本身就有 /api就不需要 rewrite
// 如果你希望把 /api 前缀去掉再转发,就打开下面这行:
// rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
})