uni 设置代理服务器,解决跨域问题
1、在mainfest.json中加入代码段
-
注:“pathRewrite”:{"^/dpc":""} 不设置则代理不起效
"h5": {
"devServer": {
"port": 8080,
"disableHostCheck": true,
"proxy": {
"/dpc": {
"target": "http://Ip:port",
"changeOrigin": true,
"secure": false,
"pathRewrite":{"^/dpc":""}
}
}
}
2、在请求中使用’/dpc’代理请求baseurl(http://Ip:port)
uni.request({
url:'/dpc/login.do',
data,
method: 'post',
complete:({data})=>{
console.log(data);
}
})