当前位置: 移动技术网 > IT编程>开发语言>JavaScript > axios访问多个服务器地址请求数据

axios访问多个服务器地址请求数据

2020年07月08日  | 移动技术网IT编程  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网