【发布时间】:2023-03-15 04:44:01
【问题描述】:
我正在开发一个调用外部 API 的 VueJS 应用程序。当我这样做时:
this.$http.get(myAPIurl)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
});
我在 chrome 控制台中遇到这 2 个错误。
Refused to set unsafe header "Access-Control-Request-Method"
XMLHttpRequest cannot load http://xxxxxx Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access
我该怎么做?
【问题讨论】:
-
你的后端 API-myAPIurl 的服务器是什么
-
@saurabh 我正在使用 musixmatch API,所以它是第三方服务器。
标签: cross-domain vue.js same-origin-policy