<component v-for="(item, index) in message" :key="index" :is="item.component" :ref="setComponentRef(index)" />
const componentRefs = ref({});
const setComponentRef = (index) => (el) => {
componentRefs.value[index] = el;
};
onMounted(async () => {
await nextTick(); // 等待 DOM 更新
for (const index in componentRefs.value) {
const dynamicComponentRef = componentRefs.value[index]?.$el;
// 在这里你可以操作动态组件的 DOM,例如获取属性、添加事件监听器等
console.log(dynamicComponentRef);
}
});
动态获取遍历的组件的所有节点
最新推荐文章于 2024-07-25 21:13:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)