点赞哦~ 直接放源码
![9340a0ce3c3f4157de4fb699cd3b9bfa.png](https://i-blog.csdnimg.cn/blog_migrate/7f25d20c877fcdb976e1b31cdb928a47.jpeg)
// 获取节点宽度
async getDom() {
var that = this
var query = wepy.createSelectorQuery();
query.select('.test').boundingClientRect()
await query.exec((res)=> {
var dom_w = res[0].width
that.dom_w = dom_w
})
}
// 方法调用
var a = setInterval(()=> {
this.getDom()
if (that.dom_w > 120) {
console.log("超过了")
that.testSize -= 1
that.$apply()
clearInterval(a)
//结束循环
// break;
} else {
console.log("未达到")
that.testSize += 1
that.$apply()
}
console.log(that.testSize, '字体大小')
}, 100)
注意点:本想用循环,但是小程序的dom节点操作api属于异步操作,所以采用定时器的方式