vue.config.js可以配置跨域访问,没有就创建一个
module.exports = {
devServer: {
host: "0.0.0.0",
port: 8080,
// 配置跨域地址
open: true,
proxy: {
// 跨域的第一台服务器路径以aaa开头的
'/aaa': {
// 允许跨域的的公网路径
target: 'http://111.111.111.111:8888',
changeOrigin: true,
pathRewrite: {
'^/aaa': ''
}
},
// 跨域的第二台服务器路径以bbb开头的
'/bbb': {
// 允许跨域的的公网路径
target: 'http://222.222.222.222:9999',
changeOrigin: true,
pathRewrite: {
'^/bbb': ''
}
},
}
},
}
this.$axios.post("/aaa/post").then(res => {
})
this.$axios.post("/bbb/upload").then(res => {
})
关掉重启,关掉重启,关掉重启,配置才能生效