美文网首页
wepy使用Promise简易封装请求

wepy使用Promise简易封装请求

作者: 天字一等 | 来源:发表于2019-05-21 18:14 被阅读0次

network/request.js

//封装ajax请求

const http = (url,type,parameter) => {
  return new Promise((resolve,reject) => {
    wx.request({
      url:url,
      method:type,
      success:function (res) {
        resolve(res.data);
      },
      fail:function (err) {
        reject(err)
      }
    })
  })

}

export {http}

在index.wpy中使用

    import { http } from '../network/request';
    http("https://easy-mock.com/mock/5cc66aee7a9a541c744c9c07/example/restful/:id/list","GET").then(function (res) {
      console.log(res)
    }).catch(function (err) {
    
    });

相关文章

网友评论

      本文标题:wepy使用Promise简易封装请求

      本文链接:https://www.haomeiwen.com/subject/djqszqtx.html