axios访问多个服务器地址请求数据
程序员文章站
2022-10-25 12:27:55
axios访问多个服务器地址请求数据在vue.config.js里配置devServer: {proxy: {'/api': {target: "http://www.baidu.com",changeOrigin: true,secure: false,pathRewrite: {"^/api": ""}},'/api2': {target: "http://www.taobao.com",changeOrigin...
axios访问多个服务器地址请求数据
在vue.config.js里配置
devServer: {
proxy: {
'/api': {
target: "http://www.baidu.com",
changeOrigin: true,
secure: false,
pathRewrite: {
"^/api": ""
}
},
'/api2': {
target: "http://www.taobao.com",
changeOrigin: true,
secure: false,
pathRewrite: {
"^/api2": ""
}
},
},
before: app => {}
},
用法:
api.defaultAxios({
url: '/api/getdata',
method: 'get',
headers: {
'content-type': 'application/x-www-form-urlencoded',
},
params: {
key: value,
}
}).then(res => {
console.log(res)
})
只为记录,防止自己下次忘了,看不懂可以留言,所以请轻喷.
本文地址:https://blog.csdn.net/qq_41585377/article/details/107102014