VS code 配置 Vue axios 跨域请求

VS code 配置 Vue axios 跨域请求

第一步:
config/index.js
//跨域配置
proxyTable: {
‘/api’: {
target: ‘http://ip:端口’, // 后台访问地址 接口的域名
// secure: false, // 如果是https接口,需要配置这个参数
changeOrigin: true, //允许跨域 如果接口跨域,需要进行这个参数配置
pathRewrite: {
‘^/api’: ‘’
}
}
},
第二步:
axios 请求时 添加一个请求header
axios.post(url,参数,{
headers: {
‘Content-Type’: ‘application/json;;charset=UTF-8’
}}).then(function(response) {

}).catch(function (error) {
		    	
})

你可能感兴趣的:(axios)