在vite.config.js中(没有的话新建一个) server: { port: 3000, proxy:{ '/api':{ // 实际请求地址 target:'http://172.16.1.100:30002', changeOrigin:true, rewrite:(path)=>path.replace(/^/api/,'') } } } 注意 封装接口的时候/api/XXX /api 为正则匹配标识 在浏览器中查看请求url时 ,http://本地代理/api => http://172.16.1.100:30002