unapp 开发微信小程序 使用wx.createSelectorQuery()时候一直获取不到元素信息。

在自定义组件中,使用wx.createSelectorQuery() 不能用wx. 而是this.createSelectorQuery()

微信文档:

 但是在uni的官方文档中并没有关于需要切换this的介绍,是用uni.createSelectorQuery()在自定义组件内部也是无效的。

 以下是我在项目中使用的场景:

在通过接口获取新数据并渲染之后,再调用下面这种方式可以准确拿到dom信息。(定时器的话根据页面渲染快慢决定是否去掉)

this.$nextTick(() => {
							this.timer = setTimeout(() => {
								this.createSelectorQuery().select(".pinglunDom").boundingClientRect(function(rect) {
									console.log(rect);
									that.pingjiaBoxMaxHeight = rect.height
								}).exec();
							}, 0)
						})

猜你喜欢

转载自blog.csdn.net/m0_57033755/article/details/132563370