编译环境 HbuilderX 3.4.18 windows11
需求:在custom 页面里引入了 tuandan-plate 组件。 需要获取组件信息
解决问题:
1. 在custom 页面 的 tuandan-plate 组件上添加 id="plate",
2. 在 tuandan-plate 组件里的 mounted() 去获取 id
操作:
mounted() {
this.$nextTick(() => {
uni.createSelectorQuery().in(this).select('#plate').boundingClientRect().exec(rect => {
console.log('rrrr``2', rect)
});
})
},
下面是截图:
1. 给组件添加id="plate"
2. 不用在组件里重复添加id (我当前情况在这里面给 id是没有用的,试了好久才找到原因。也是我对dom节点信息不熟悉导致的。)
3. 在mounted里执行
4. 拿到想要得