import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { fileURLToPath, URL } from 'node:url' export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, // --- 新增下面这一段 server 配置 --- server: { proxy: { '/api': { target: 'http://127.0.0.1:5000', // 后端的地址 changeOrigin: true, // 如果你的后端路径本身就包含 /api,通常不需要 rewrite // rewrite: (path) => path.replace(/^\/api/, '') } } } })