From c496816d49f6ece4406b1ef4b062309950e36a6a Mon Sep 17 00:00:00 2001 From: jixinbao Date: Wed, 17 Jul 2024 11:34:32 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20createSelectorQuer?= =?UTF-8?q?y=20=E7=BB=84=E5=90=88=E5=BC=8F=20API=20=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/ui/nodes-info.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/api/ui/nodes-info.md b/docs/api/ui/nodes-info.md index 5b00948b9..81c5f3832 100644 --- a/docs/api/ui/nodes-info.md +++ b/docs/api/ui/nodes-info.md @@ -19,6 +19,10 @@ **代码示例** +::: preview + +> 选项式 API + ```javascript const query = uni.createSelectorQuery().in(this); query @@ -30,6 +34,22 @@ query .exec(); ``` +> 组合式 API + +```javascript +import { getCurrentInstance } from 'vue'; +const instance = getCurrentInstance(); + +const query = uni.createSelectorQuery().in(instance.proxy); +query + .select("#id") + .boundingClientRect((data) => { + console.log("得到布局位置信息" + JSON.stringify(data)); + console.log("节点离页面顶部的距离为" + data.top); + }) + .exec(); +``` + **注意** - 支付宝小程序不支持 in(component),使用无效果 -- GitLab