第一次上手uniapp做项目, 碰到的坑-前端ajax请求 报跨域问题.
1. 服务器真实没有处理解决跨域问题
配置 uni-app 中 manifest.json->h5->devServer
"h5": {
"devServer": {
"port": 8080,//端口
"disableHostCheck": true,
"proxy": {
"/api": {
"target": "http://www.xxxxx.net",//目标接口域名
"changeOrigin": true,//是跨域
"secure": false,//设置支持https协议的代理
}
}
}
}
其中参数解析详见: https://www.jb51.net/article/180961.htm
更多其他解决方式详见: https://ask.dcloud.net.cn/article/35267
2. 服务器端已处理解决跨域问题,但访问仍然跨域错误
Access to XMLHttpRequest at 'http://xxxxx.com/api/public/getLiveClass' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doe

本文详细介绍了在uniapp开发中遇到的跨域问题及解决方法。包括在manifest.json中配置代理解决跨域,以及调整uview的http请求工具中content-type参数,以确保请求正确发送,适用于前后端分离的项目。
最低0.47元/天 解锁文章
1712

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



