限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >小程序

小程序 | loading与promise all

分类:小程序时间:2018-10-07浏览:3951
加载loading
 wx.showLoading({
      title: '加载中',
    })


关闭
loadingwx.hideLoading()
并行发送多个请求,使用promise.all
/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    })
    const bid = options.bid
    const detail = BookModel.getDetail(bid)
    const comments = BookModel.getComments(bid)
    const likeStatus = BookModel.getLikeStatus(bid)

    // ----组合多个------
    Promise.all([detail,comments,likeStatus])
    .then(res=>{
      this.setData({
        book:res[0],
        comments: res[1].comments,
        likeStatus: res[2].like_status,
        likeCount: res[2].fav_nums,    
      })
    })
    wx:wx.hideLoading()


    // ----------
    
    // detail.then(res=>{
    //   console.log(res)
    //   this.setData({
    //     book:res
    //   })
    // })

    // comments.then(res => {
    //   console.log(res)
    //   this.setData({
    //     comments: res.comments
    //   })
    // })

    // likeStatus.then(res => {
    //   console.log(res)
    //   this.setData({
    //     likeStatus: res.like_status,
    //     likeCount: res.fav_nums,        
    //   })
    // })
   
  },
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.