配置uni-app 中 manifest.json->h5->devServer
manifest.json
"h5" : {
"devServer" : {
"https" : false,
"port": 80,
"disableHostCheck": true,
"proxy": {
"/api/v1/": {
"target": "http://test.cn/api/v1/",
"changeOrigin": true,
"secure": false,
"pathRewrite":{"^/api/v1/":""}
}
}
}
}
http请求
uni.request({
url: "/api/v1/index/index", //仅为示例,并非真实接口地址。
success: (res) => {
console.log(res);
}
});
配置完成之后, 一定要重启 uniapp
很多人都有解决方案,大概都差不多 ,这里只是做一个归纳总结,亲测可用