一、根據wepy官方給的文檔以下,用then拿後臺返回的數據,若是用then報錯,請先在app.wpy中配置promise。json
沒有success,fail,complete方法,如若用了也是不會進入方法的,意味着拿不到後臺返回的數據。promise
// 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); }
二、向後臺傳參、設置請求頭、獲取後臺返回數據app
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, }) })