vue.config.js中配置代理
module.exports = {
devServer: {
host: "0.0.0.0",
port: 8082,
proxy: {
// 第一台服务器配置
"/api1": {
target: "http://127.0.0.1:3007",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/api1": "",
},
},
// 第二台服务器配置
"/api2": {
target: "http://127.0.0.1:3008",
ws: true,
changeOrigin: true,
pathRewrite: {
"^/api2": "",
},
},
},
},
};
封装axios时建立两个axios连接
import theAxios from "axios";
const axios1 = theAxios.create({
baseURL: "/api1",
timeout: 20000,
})
const axios2 = theAxios.create({
baseURL: "/api2",
timeout: 20000,
})
//....