一、使用Hbuilder右上角的预览,Hbuilder内置浏览器调试跨域忽略掉跨域问题
二、修改vue.config.js配置文件
1.在devServer{}内加入代理
devServer: {
proxy: { //配置跨域
'/host': {
target: 'https://xxx.xxx.com', //这里后台的地址模拟的;应该填写你们真实的后台接口
changOrigin: true, //允许跨域
pathRewrite: {
'^/host': ''
}
},
},
disableHostCheck: true
}
2.在需要使用域名的地方使用“host”即可
例如我这里有一个api.js统一管理接口列表的
以上就是解决uniapp中开发h5发生跨域的解决办法了。
补充:在api管理处,var http='host',可写成'/host/'或者'/host',即
var http = '/host/'
或
var http = '/host'
具体要看后面拼接的路径,尤其是后端接口类似:xxx.com/**host**/us…