Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
79
rated 0 times [  85] [ 6]  / answers: 1 / hits: 80467  / 8 Years ago, thu, march 3, 2016, 12:00:00

I'm trying to access a specific child by name. At the moment, because of where the child is, I'm calling the child by this:



this.$root.$children[0]


Which is ok as long as that child is always [0] but it would be great if there’s a way to do something like:



this.$root.$children['detail']


I keep thinking $refs might be the answer to my problem but can never find a way that it helps me.



Any ideas?


More From » vue.js

 Answers
0

Is this child you are talking about really a child of the component that you want to access it from? In this case, v-ref is indeed the answer:





// in the code of the parent component, access the referenced child component like this:

this.$refs.detailsChild

<!-- Template of the parent component, assuming your child Component is called Details -->
<details v-ref:details-child></details>





relevant API Documentation: http://vuejs.org/api/#v-ref


[#63072] Tuesday, March 1, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gonzalo

Total Points: 336
Total Questions: 114
Total Answers: 98

Location: Iceland
Member since Sat, Sep 17, 2022
2 Years ago
;