小程序 | loading与promise all
加载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,
// })
// })
}, 本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。