const proxy = require('http-proxy-middleware'); module.exports = { devServer:{ host: 'localhost',//target host port: 8080, //proxy:{'/api':{}},代理器中設置/api,項目中請求路徑為/api的替換為target proxy:{ '/api':{ target: 'http://192.168.1.30:8085',//代理地址,這里設置的地址會代替axios中設置的baseURL changeOrigin: true,// 如果接口跨域,需要進行這個參數配置 //ws: true, // proxy websockets //pathRewrite方法重寫url pathRewrite: { '^/api': '/' //pathRewrite: {'^/api': '/'} 重寫之后url為 http://192.168.1.16:8085/xxxx //pathRewrite: {'^/api': '/api'} 重寫之后url為 http://192.168.1.16:8085/api/xxxx } }} }, //... }