uni-app跨域解决方案(踩坑)
https://blog.csdn.net/paopao79085/article/details/91948809?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10-91948809-blog-119762446.pc_relevant_blogantidownloadv1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10-91948809-blog-119762446.pc_relevant_blogantidownloadv1&utm_relevant_index=13
配置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);
}
});
经过多方试验,终于找到了解决办法,proxy里加入
"proxy": {
"/dpc": {
"target": "http://dpc.dapeis.net",
"changeOrigin": true,
"secure": false,
"pathRewrite":{"^/dpc":""}
}
}
如果proxy配置"/api",则不需要配pathRewrite,如果叫别的名字就要配pathRewrite