vue.config.js
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://api.example.com', // 项目地址
changeOrigin: true,
pathRewrite: {
'^/api': '' // 去除请求路径中的"/api"部分
}
},
'/otherApi': {
target: 'http://another-api.example.com', // 将此处的URL更换为其他API地址
changeOrigin: true,
pathRewrite: {
'^/otherApi': '' // 去除请求路径中的"/otherApi"部分
}
}
}
}
}
接口
export const reqOtherData = (data) => {
return request({
//request文件都有配置好baseURL,
//可以单独配置baseURL,来访问其他网址的接口
baseURL: '/otherApi',
url:"/example/example/example",
method:"get",
params:data
});
};