vue 跨域请求


post请求在config -> index.js 下
1:pathRewrite 重定向进行删除
proxyTable: {
'/api': {
target: 'http://xxxxxx/',
changeOrigin: true,
/* pathRewrite: {
'^/api': ''
}*/
}
页面:
axios.post('/api/xxx',{
LoginName :'LoginName',
LoginPwd :'LoginPwd',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(function(response){
var that = this
that.username = response.data.LoginName
that.password = response.data.LoginPwd
})
.catch(function(error){
console.info(error)
})
===================================================================================================================================================
2:get 请求 不需要删除

pathRewrite
页面:

axios.get('/api/xxx').then( res=> {
  var _this = this
_this.WD = res.data.subjects
}).catch (error => {
console.log(error)
})
npm run dev
原文地址:https://www.cnblogs.com/Kipper-liu/p/8597771.html