获取元素的高度,并根据高度做一些操作。
使用this.$nextTick()的原因:当页面的数据还没有渲染完成的时候,获取的元素是undefined,所以要等所有的节点都渲染完成之后,才能操作。
this.$nextTick(() => {
const query = uni.createSelectorQuery().in(this);
query
.select(".errorDesc")
.boundingClientRect((rect) => {
let height = rect.height;
console.log("height: ", height);
if (height > 50) {
this.showMoreFont = true;
this.btnShow = 1;
}
})
.exec();
});