var query = uni.createSelectorQuery().in(this);
query.selectViewport().scrollOffset()
query.select('#content').boundingClientRect();
query.exec(function(res) {
console.log(res)
});

- 发布:2022-02-25 11:11
- 更新:2025-09-01 16:03
- 阅读:7258
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows10
HBuilderX类型: 正式
HBuilderX版本号: 3.3.12
第三方开发者工具版本号: 1.05.2201240
基础库版本号: 2.22.0
项目创建方式: HBuilderX
操作步骤:
预期结果:
获取dom元素的节点
获取dom元素的节点
实际结果:
VM1578 WAService.js:2 Unhandled promise rejection TypeError: Cannot read property 'route' of undefined
VM1578 WAService.js:2 Unhandled promise rejection TypeError: Cannot read property 'route' of undefined
bug描述:
在vue3使用uni.createSelectorQuery()获取不到dom元素节点信息

import {getCurrentInstance,} from 'vue';
const instance = getCurrentInstance();
const query = uni.createSelectorQuery().in(instance);
query.select('.selfnodes').boundingClientRect(data => {
if (data) {
console.log("获取到布局信息", data);
}
}).exec();
微信小程序、字节小程序递归组件中亲测可行

问题确认,后续优化,已加分,感谢您的反馈!

以下代码测试在4.76版本的hx上运行并没有报错,可参考下方代码修改测试是否还有报错
<template>
<view style="font-size: 80rpx;">
<view id="test">首页</view>
</view>
</template>
<script setup>
import {
getCurrentInstance,
onMounted
} from 'vue';
const ins = getCurrentInstance()
onMounted(() => {
const query = uni.createSelectorQuery().in(ins.proxy)
query.select('#test').boundingClientRect(data => {
console.log("data", data);
}).exec();
})
</script>
9***@qq.com
大佬,感谢
2022-06-08 11:02
3***@qq.com
感谢大佬
2022-09-07 10:53
奇怪的牛马1
第三方组件内怎么获取啊?
2025-01-03 11:54