uniapp异步请求编写框架

参考:https://blog.csdn.net/weixin_48393490/article/details/130126657

 

框架:

async function fun() {
  return new Promise((resolve, reject) => {
    uni.request({
      url: 'https://www.example.com/request',
      data: {
        name: 'name',
        age: 18
      },
      success: function (res) {
        resolve(res.data); // 解决 Promise 并传递数据
      },
      fail: function (err) {
        reject(err); // 拒绝 Promise 并传递错误
      }
    });
  });
}




//调用(vue):
async fasong(nr) {
  var jg = await oks.fun(nr)
  console.log(jg);
},

uniapp请求参数:

地址:https://uniapp.dcloud.net.cn/api/request/request.html

posted @ 2023-10-21 11:16  哲_心  阅读(14)  评论(0编辑  收藏  举报