问题描述

uni-app 前端请求后端数据时候出现错误

Access to XMLHttpRequest at 'http://localhost:8002/bmft/jingdong/list/java' 
from origin 'http://localhost:8080' has been blocked by CORS policy: 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.

request doesn’t pass access control check
这是不允许跨域请求的原因

前端解决(推荐)

https://segmentfault.com/a/1190000017911280
官方教程:
https://ask.dcloud.net.cn/article/35267

2.配置uni-app 中 manifest.json->h5->devServer
manifest.json

    "h5": {
        "devServer": {
            "port": 8000,
            "disableHostCheck": true,
            "proxy": {
                "/dpc": {
                    "target": "http://dpc.dapeis.net",
                    "changeOrigin": true,
                    "secure": false
                }
            }
        }
    }
后端解决方法

SpringBoot解决跨域请求的方法(其他请自行百度十分简单
给controller加上注解 @CrossOrigin("http://localhost:8080")
例如
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐