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/