在项目根目录新建vue.config.js输入
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://www.example.com:81/', //接口域名,端口看各自设置的
changeOrigin: true, //是否跨域
ws: true, //是否代理 websockets
secure: true, //是否https接口
pathRewrite: { //路径重置
'^/api': ''
}
}
}
}
};
如用到的是vite.config.js则在这个文件添加
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://www.example.com:81', //接口域名,端口看各自设置的
changeOrigin: true, //是否跨域
ws: true, //是否代理 websockets
secure: true, //是否https接口
pathRewrite: { //路径重置
'^/api': ''
}
}
}
}
};