manifest.json文件里面進行配置

用以下代碼可以正確的請求到數據: //注意下面的 "pathRewrite"是必要的,不然讀取不到數據 "h5": { "devServer": { "port": 8000, "disableHostCheck": true, "proxy": { "/api": { "target": "https://api.ithome.com", //請求的目標域名 "changeOrigin": true, "secure": false, "pathRewrite": { //使用代理; 告訴他你這個連接要用代理 "^/api": "/" } } } } } 2.在.vue頁面中添加 code:function(){//注意這里的/api就是上面manifest.json文件配置的devServer中的proxy uni.request({ url: '/api/index/user/sendSms', //僅為示例, method:"POST", data: { "username": "13183539531", "password": "123456" }, header: {'Content-type':'application/json'}, success: (res) => { // console.log(res.data); } }); },
注意:配置完,需要重啟服務才行
