【发布时间】:2020-09-24 06:54:51
【问题描述】:
我正在尝试使用 axios 和 vue.js 向有效服务器发送 get 请求,但我不断收到 Access to XMLHttpRequest at 'http://37.152.185.50:8080/hotels/tblisi' from origin 'http://localhost:63342' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 我尝试设置 Content-Type 标头但没有运气。我在另一个项目中也遇到了与 axios 和 vue.js 相同的问题,显然对其他人来说效果很好。
vm = new Vue({
el: '#main-container',
data: {
city: 'istanbul',
hotels: []
},
methods: {
setCity: function (city) {
this.city = city;
axios({
method: 'get',
data: {},
url: 'http://37.152.185.50:8080/hotels/' + this.city,
headers: {
'content-type': 'application/x-www-form-urlencoded',
}
});
}
}
});
我也无权访问服务器来更改响应标头。
【问题讨论】: