module.exports = {
runtimeCompiler: true,
publicPath: '/', // 设置打包文件相对路径
devServer: {
// open: process.platform === 'darwin',
// host: 'localhost',
port: 8080,
// open: true, //配置自动启动浏览器
proxy: {
'/api': {
target: 'http:// 192.168.1.1:8080', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
},
};
参数说明
target: 接口域名
changeOrigin: true, 表示是否跨域
pathRewrite: {‘^/api’: ”} 表示需要rewrite重写的,
配置好这写之后就可以直接使用/api+接口名称发送请求了
例如:原来的请求地址为 192.168.1.1:8080/log
配置代理后直接使用 /api/log 就可以了