admin管理员组文章数量:1287624
Problem
I'm working with a Vue CLI application. There is a grandchild ponent that needs access to another ponent's element's properties. It really only needs the clientHeight
property.
So Content2.vue ponent needs access to the clientHeight
property of this element: <div id="header"></div>
(in Header.vue).
Attempted Solutions
I've tried using
$refs
. And according to this stackoverflow answer$refs
are only available to ponents directly related as parent/child.I've also considered adding the
$refs
orclientHeight
to the store (vuex), but its seems like overkill.I could always go vanilla and use querySelector or getElementById. But thought there may be something better.
Thanks for your help!
Problem
I'm working with a Vue CLI application. There is a grandchild ponent that needs access to another ponent's element's properties. It really only needs the clientHeight
property.
So Content2.vue ponent needs access to the clientHeight
property of this element: <div id="header"></div>
(in Header.vue).
Attempted Solutions
I've tried using
$refs
. And according to this stackoverflow answer$refs
are only available to ponents directly related as parent/child.I've also considered adding the
$refs
orclientHeight
to the store (vuex), but its seems like overkill.I could always go vanilla and use querySelector or getElementById. But thought there may be something better.
Thanks for your help!
Share Improve this question asked Oct 1, 2019 at 22:29 RyanRyan 5706 silver badges20 bronze badges 2-
It seems like you are aware of all the possible solutions. My personal remendation would be to use
vuex
. You will get a lot of mileage out of learning and familiarizing yourself withvuex
. It might seem like overkill for this particular use case, but I think a simple case like this might be the best way to learn how to use it. The added bonus is, then it's already in place for the next time you need to reach for it.本文标签: javascriptHow to access Vue component element property from sibling componentStack Overflow
版权声明:本文标题:javascript - How to access Vue component element property from sibling component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741316575a2371949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论