在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 微信小程序獲取節(jié)點(diǎn)信息,為什么有的時(shí)候有,有的時(shí)候就是空的?

微信小程序獲取節(jié)點(diǎn)信息,為什么有的時(shí)候有,有的時(shí)候就是空的?

自定義組件生命周期res.height有的時(shí)候報(bào)null

ready: function () {

var that = this
var query = wx.createSelectorQuery().in(this)
query.select('.question').boundingClientRect(function (res) {
  that.setData({
    questionHeight: res.height
  })
}).exec()
// console.log(that.data.questionHeight)

}

回答
編輯回答
怣痛

你的console.log得寫到回調(diào)函數(shù)里面,不然會(huì)出現(xiàn)boundingClientRect還未觸發(fā)回調(diào)、并setData的操作,而先執(zhí)行了console。

2018年8月17日 16:38
編輯回答
獨(dú)白

可能是加載的生命周期問題。
寫在onShow()下試試

2017年7月19日 15:29