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,
          })
        })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM