解决uni-app在H5端的跨域问题
·
问题报错截图:这是常见的前端浏览器跨域问题了

解决方法
修改 manifest.json 文件,新增 H5 的跨域配置(使用 源码视图打开配置文件)
// h5端跨域配置
"h5": {
"devServer": {
"disableHostCheck": true,
"proxy": {
"/api": {
"target": "http://xxxxxxxx",
"changeOrigin": true,
"secure": false,
"pathRewrite": {
"^/api": ""
}
}
}
}
}
如何请求
把 H5 端的请求地址前缀改为 /api
uni.request({
// #ifdef H5
url: '/api/postclass',
// #endif
// #ifdef APP-PLUS
url: this.config.webUrl + '/postclass',
// #endif
method: 'GET',
success: res => {
console.log(res)
},
fail: () => {},
});
更多推荐
所有评论(0)