vue在开发的时候代理接口配置
在vue.config.js中
module.exports={
···
devServer:{
···
porxy:{
'/api': { // 调用的接口前缀
target: "http://192.168.x.xxx:6180", // 代理的ip+port
changeOrigin: true, // 是否允许跨域
secure: false, // 是否是https请求
pathRewrite: { // 替换url中的某个字符串
'^/api': ''
}
},
}
}
···
}
例如:
request({
url:'/archive/page'
})
那么真实请求地址为
http://192.168.x.xxx:6180/archive/page
如果没有pathRewrite,则真是请求地址为
http://192.168.x.xxx:6180/api/archive/page