美文网首页
uni-app 解决h5跨域问题

uni-app 解决h5跨域问题

作者: meryin | 来源:发表于2022-12-14 11:34 被阅读0次

报错:
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' ,

相关文章

网友评论

      本文标题:uni-app 解决h5跨域问题

      本文链接:https://www.haomeiwen.com/subject/kxjhqdtx.html