Categories
Vue Answers

How to check if a component exists with Vue.js?

Spread the love

Sometimes, we want to check if a component exists with Vue.js.

In this article, we’ll look at how to check if a component exists with Vue.js.

How to check if a component exists with Vue.js?

To check if a component exists with Vue.js, we can check if the component name exists as a property key in the $options.components property.

For instance, we write

this.$options.components[componentName];

to check if the component with name set to componentName‘s value exists in the current component instance.

Likewise, we can do the same check for global components with

Vue.$options.components[componentName]

Conclusion

To check if a component exists with Vue.js, we can check if the component name exists as a property key in the $options.components property.

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 *