uni-app 解决h5跨域问题

报错:
Access to XMLHttpRequest at 'https://xxxxxxx.com/api/v1/ios/users' 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.

解决方案:
首先: manifest.json文件中

"h5" : {
"devServer" : {
"disableHostCheck" : true,
"host": "localhost",
"port": "8080",
"proxy" : {
"/api" : {
"target" : "https://xxxxxx.com",
"changeOrigin" : true,
"secure" : true,
"ws" : true,
"pathRewrite" : {
"^/api": ""
}
}
}
}
}

然后:在http请求头设置那里 设置 config.baseURL = '/api' ,

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容