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/