Vue.js: check if a component exists

前端 未结 6 1416
天命终不由人
天命终不由人 2021-02-12 13:26

I need to do some stuff in the ready: of the root instance only when some components don\'t exist (they weren\'t declared in the HTML).

How can I check if a

6条回答
  •  后悔当初
    2021-02-12 14:01

    To check if a global component exists:

    let componentExists = 'componentName' in Vue.options.components
    

    To check if a imported component exists in a component:

    let componentExists = 'componentName' in this.$options.components
    

提交回复
热议问题