沒有找到好的方法或者官方的相關API
1)嘗試了網上說的這個,但是onready只調用一次,所以這個寫了定時器也還是執行一次:
setTimeout(() => {
let _this = this
wx.createSelectorQuery().select('#container-title').boundingClientRect(function (rect) {
width = rect.width
height = rect.height
top = rect.top
}).exec()
},300)
2)還是把這個獲取頁面高度的方法寫成的公共的方法,然後進行改變頁面高度的操作(比如新增刪除、顯示隱藏)的時候就調用一下這個方法
onReady: function () {
//動態獲取高度
this.autoHeight();
},
//動態獲取高度
autoHeight:function(){
var that = this;
var query = wx.createSelectorQuery();
query.select('.container').boundingClientRect(function(rect) {
console.log("----w" + rect.height)
that.setData({
windowHeight: rect.height ,//獲取頁面高度
})
}).exec();
},
還是有點麻煩其實,後續找到更好的解決辦法再進行更新……