当前位置:   article > 正文

uniap vue3 组件使用uni.createSelectorQuery() 获取dom报错

uniap vue3 组件使用uni.createSelectorQuery() 获取dom报错

由于vue3中没有this,所以使用uni.createSelectorQuery().in(this)时,会报错
在这里插入图片描述
使用 getCurrentInstance 获取组件实例
使用 uni.createSelectorQuery() 批量查询时,结果是按照查询的顺序返回的

  • 使用示例
import { getCurrentInstance } from 'vue'
const appInstance = getCurrentInstance().proxy

onMounted(() => {
	let query = uni.createSelectorQuery().in(appInstance)
	query
		.select('.scroll_view')
		.boundingClientRect((rect) => {
			top.value = rect.top || 0
		})
		.exec()
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/453848
推荐阅读