axios访问多个服务器地址请求数据
程序员文章站
2022-04-30 13:03:03
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
下一篇: 这就是传说中的三角恋,你爱她,也爱着他!