uni-app跨域请求解决方案
1.官方推荐
2.配置uni-app 中 manifest.json->h5->devServer
manifest.json
"h5": {
"title" : "项目",
"domain" : "127.0.0.1",
"router" : {
"mode" : "history",
"base" : "/h5/"
},
"devServer": {
//"https" : false,
//"port": 8000,
//"host" : "127.0.0.1",
//"disableHostCheck": true,
"proxy": {
"/dpc": {
"target": "http://127.0.0.1:3000",//目标接口域名
"changeOrigin": true,//允许跨域
"secure": false,// 设置支持https协议的代理
// "pathRewrite":{
// "^/dyh":"" //替换为空 自己填写的
// }
}
}
}
}
http请求
uni.request({
url: '/api/getUserInfo',
success: (res) => {
console.log(res.data);
}
});
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634588.html