Categories
Vue Answers

How to get $children by component name with Vue.js?

Spread the love

Sometimes, we want to get $children by component name with Vue.js.

In this article, we’ll look at how to get $children by component name with Vue.js.

How to get $children by component name with Vue.js?

To get $children by component name with Vue.js, we can call find on this.$root.$children.

For instance, we write

this.$root.$children.find((child) => {
  return child.$options.name === "name";
});

to find the child component with the name option set to 'name'.

Conclusion

To get $children by component name with Vue.js, we can call find on this.$root.$children.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *