Reputation: 7447
I am migrating a project from Vue 2 to Vue 3. I need to determine if a component is loaded and if it isn't, load a GenericComponent as a placeholder. In Vue 2 I was able to do it with the sample code. I have been reading the Vue 3 docs but I am unable to find anything about this.
import Vue from 'vue'
import GenericComponent from 'components/GenericComponent'
if (!Vue.options.components['custom-component']) {
Vue.component('custom-component', GenericComponent)
}
Upvotes: 1
Views: 898
Reputation: 8726
You can do like this:
import { getCurrentInstance } from 'vue';
const app = getCurrentInstance()
console.log('app component', app?.appContext.components['component-name'])
Note that appContext.components
will only contain global components.
Upvotes: 1