[英]How to solve this 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control in vueJS?
Access to XMLHttpRequest at ' http://localhost/webserivcedemo/state.php ' from origin ' http://localhost:8080 ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The
Access-Control-Allow-Origin
header contains multiple values*, *
,but only one is allowed.访问的XMLHttpRequest在' :HTTP //localhost/webserivcedemo/state.php从原点“的http://本地主机:8080 ”已被封锁的CORS政策:回应预检要求未通过访问控制检查:
Access-Control-Allow-Origin
标头包含多个值*, *
,但只允许一个。
I use $http for call webservice.我使用 $http 调用网络服务。 This is my request code.
这是我的请求代码。
export default {
data() {
return {
name: "",
number: "",
email: "",
submitdata: false
};
},
methods: {
handleSubmit: function() {
var data1 = {
title: this.name,
body: this.number + this.email
};
this.$http
.post("http://localhost/webserivcedemo/state.php", {
data: data1
})
.then(function(data) {
console.log(data);
this.submitdata = true;
});
}
}
};
you need to create new file vue.config.js
and need to add the urls that are needed to access as below.您需要创建新文件
vue.config.js
并需要添加访问所需的 url,如下所示。
module.exports = {
devServer: {
proxy: 'endpoint',
}
}
solution 1 : please check 1st same port/server like as http://127.0.0.1:8080
running twist or not?解决方案 1 :请检查第一个相同的端口/服务器,如
http://127.0.0.1:8080
运行扭曲? If twist then close one.如果扭曲然后关闭一个。 then check.
然后检查。
solution 2 : sometimes problem for extra /
API endpoint.解决方案 2 :有时会出现额外
/
API 端点的问题。 remove the extra /
then check.删除多余的
/
然后检查。
thank you谢谢你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.