uni 設置代理服務器,解決跨域問題
1、在mainfest.js中加入代碼段
-
注:“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);
}
})