1、根據wepy官方給的文檔如下,用then拿后台返回的數據,如果用then報錯,請先在app.wpy中配置promise。
沒有success,fail,complete方法,如若用了也是不會進入方法的,意味着拿不到后台返回的數據。
// WePY 使用方式, 需要開啟 Promise 支持,參考開發規范章節 wepy.request('xxxx').then((d) => console.log(d)); // async/await 的使用方式, 需要開啟 Promise 和 async/await 支持,參考 WIKI async function request () { let d = await wepy.request('xxxxx'); console.log(d); }
2、向后台傳參、設置請求頭、獲取后台返回數據
wepy.request( { url:url, data:serviceParams, header: { 'content-type': 'application/x-www-form-urlencoded ' }, dataType:'json', method:'POST' }) .then((res) =>{ //后台返回的數據 console.log(res) }) .catch((res)=>{ wepy.showToast({ title:'請求失敗', icon:'none', duration:2000, }) })