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.