manifest.json 源码配置:
"h5": {
"router": {
"mode": "history"
},
"devServer": {
"port": 8000,
"disableHostCheck": true,
"proxy": {
"/api": {
"target": "http://**.com", //目标接口域名
"changeOrigin": true, //是否跨域
"secure": false ,// 设置支持https协议的代理
"pathRewrite":{
"^/api":""
}
}
}
}
}
request 请求:
uni.request({ //url: "/my/list"
url: "/api" + url,
data: data,
method:type||"GET",
header: {
'content-type': 'application/x-www-form-urlencoded',
},
success: (res) => {
},
fail: (res) => {
}
});

本文详细介绍了uni-app中manifest.json的配置,包括使用history模式的路由设置和devServer的代理配置,以实现与后端API的无缝对接。在请求部分展示了如何通过uni.request进行接口调用,包括URL的拼接、请求方法和Header的设定,确保了跨域请求的顺利进行。
4704

被折叠的 条评论
为什么被折叠?



