一、根据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, }) })