uni-app获取dom节点信息简单说明

<view id="iamnode">我是节点<view>

mounted() {  //获取节点信息,最好在mounted之后获取以确保获取到
    let theNode=uni.createSelectorQuery().select("#iamnode")
    theNode.boundingClientRect((data)=>{
          console.log(data)
    }).exec()
},


注:支持以下选择器
ID选择器:#the-id
class选择器(可以连续指定多个):.a-class.another-class
子元素选择器:.the-parent > .the-child
后代选择器:.the-ancestor .the-descendant
跨自定义组件的后代选择器:.the-ancestor >>> .the-descendant
多选择器的并集:#a-node, .some-other-nodes

详细文档请移步至: https://uniapp.dcloud.io/api/ui/nodes-info

猜你喜欢

转载自www.cnblogs.com/huihuihero/p/12966528.html