vue Access to XMLHttpRequest at xxx by CORS 跨域问题前端解决方式
nginx:
location /jsonapi {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' '*';
# add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, DELETE, PUT, OPTIONS';
proxy_pass http://127.0.0.1:8882/json.php;
rewrite ^/mpis/(.*)$ /$1 break;
}
vue:
axios.get('/jsonapi')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});

本文主要探讨了在Vue项目中遇到的CORS跨域问题,特别是在尝试访问PHP服务时。针对这一问题,文章提供了前端解决方案,包括如何配置Nginx服务器以允许跨域请求,并在Vue应用中设置相应的请求头。
1万+

被折叠的 条评论
为什么被折叠?



