uni解決跨域,設置代理服務

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);
	}
})  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章