代码如下
this.$axios({
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
method: "POST",
url: "http://crm.tonyliangli.cn/api/company/companyUsers",
data: {
token: "1511328705UZVQ"
}
})
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});
加上headers之后传递不过去参数
不加报错: Failed to load http://crm.tonyliangli.cn/api/company/companyUsers: Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
这是什么原因啊 来大神解答下
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
仅仅前端设置是没用的,需要后端配合, 你也可以用设置代理的方式
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
这种情况联系后台解决下
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',//开发环境
API_HOST:"/api/"
})
module.exports = {
NODE_ENV: '"production"',//生产环境
API_HOST:'"http://api.douban.com"'
}
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*'
}
headers这样配置,'Content-Type看需求
这个要后端进行配合
后端设置filter
https://blog.csdn.net/lilongwei4321/article/details/81298809