1.官方推荐cors和插件安装解决跨域
2.配置uni-app 中 manifest.json->h5->devServer manifest.json
"h5": {
"devServer": {
"port": 8000,
"disableHostCheck": true,
"proxy": {
"/dpc": {
"target": "http://dpc.dapeis.net",
"changeOrigin": true,
"secure": false
}
}
}
}http请求
uni.request({
url: '/dpc/getUserInfo',
success: (res) => {
console.log(res.data);
}});这样请求webpack会解析为请求http://dpc.dapeis.net/dpc/
参考资料:
webpack-dev-serverwebpack跨域API
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号