我是 Vue 的新手,我正在尝试使用 $refs 从兄弟组件中获取 DOM 中的一些元素(出于非常基本的目的,只是为了获取它们的高度等),我正在计算中这样做。
无论我尝试什么,this.$root.$refs要么总是返回未定义或作为空对象,我不知道我做错了什么。
在父组件中,我有:
<template>
<ComponentA />
<ComponentB />
</template>
在组件 AI 中有:
<template>
<div id="user-nav">
<div ref="nav-container">
<slot />
</div>
</div>
</template>
我只是尝试查看是否可以通过控制台日志记录在 ComponentB 中访问它
console.log(this.$root.$refs);
在该组件的已安装功能中。
但我不断得到一个空对象。
你能不能像这样跨兄弟组件访问东西???
元芳怎么了
白衣非少年
小唯快跑啊
相关分类