<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
注:uniapp目前未發現有效的方法來通過js操作一些dom。比如實現簡單的動畫效果的需求。
可以通過另外的思路,見:https://www.cnblogs.com/huihuihero/p/14871075.html

詳細文檔請移步至: https://uniapp.dcloud.io/api/ui/nodes-info