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.
文章图片
【vue解决报错 No 'Access-Control-Allow-Origin' header is present on the reques】
解决: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 =https://www.it610.com/article/= 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 = https://www.it610.com/article/result.data.data;
this.page.total = result.data.count;
// 总页数
}).catch((error)=>{
console.log(error)
})}
推荐阅读
- parallels|parallels desktop 解决网络初始化失败问题
- 考研英语阅读终极解决方案——阅读理解如何巧拿高分
- vue-cli|vue-cli 3.x vue.config.js 配置
- 2020-04-07vue中Axios的封装和API接口的管理
- MybatisPlus|MybatisPlus LambdaQueryWrapper使用int默认值的坑及解决
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- Spark|Spark 数据倾斜及其解决方案
- 解决SyntaxError:|解决SyntaxError: invalid syntax
- VueX--VUE核心插件