wepy.request 请求成功但是不进入success和fail方法,及请求传参问题

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,
          })
        })
原文地址:https://www.cnblogs.com/i-douya/p/10691940.html