可以通过设置后端服务器的响应头来解决该问题。在后端服务器的响应头中添加如下代码:
Access-Control-Allow-Origin: *
此外,在Axios中添加withCredentials和xhrFields属性可以更好地处理跨域请求。示例代码如下:
axios.get('http://example.com', {
withCredentials: true,
xhrFields: {
withCredentials: true
}
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});