使用http-proxy-middleware 代理解决(项目使用vue-cli脚手架搭建)
打开config.js,在proxy中添写如下代码:
// vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://www.XXX.net/', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'/api': '/api'
}
}
}
}
}