vue解决报错 No 'Access-Control-Allow-Origin' header is present on the reques
报错has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.解决:php后台 添加header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
·
报错has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
解决:php后台 添加
header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
还有一种情况用axios的 在请求的时候加
axios post的请求
methods: {
onSubmit() {
//提交
let formarr = {
name: this.form.name,
sex: this.form.sex,
date1: this.form.date1,
sign: this.form.sign
};
axios({
method: "post",
url: "http://xxx.com/api/index/addUser",
params: formarr,
headers: {
//fd:this.loginFrom.selectLimit, Content-Type: application/x-www-form-urlencoded
"Content-Type": "application/x-www-form-urlencoded"
// Accept:'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
// Cookie:'SESSION=MDQ2N2QzN2UtNDU5OS00MDQ1LTk4ODAtNGNlZmJlZTYyZTQ3'
}
// withCredentials:true
})
.then(result => {
console.log(result);
if (result.data == 1) {
//this.open2(); 成功提示
this.$router.push({path:'/'}) //成功之后跳转
}
})
.catch(error => {
console.log(error);
});
},
}
axios get的请求
getData: function(pageNum,pageSize) {
this.page.pageNum=pageNum || this.page.pageNum
this.page.pageSize=pageSize
axios({
method:'get',
url:"http://xxx.com/api/index/user",
params:{
pageNum:pageNum,
limit:pageSize
},
headers:{
'Content-Type':'application/x-www-form-urlencoded',
},
}).then((result)=>{
console.log(result.data)
this.tableData = result.data.data;
this.page.total = result.data.count; // 总页数
}).catch((error)=>{
console.log(error)
})
}
更多推荐
已为社区贡献7条内容
所有评论(0)