fuc-new/doc/node_modules/@vuepress/helper/lib/client/utils/hasGlobalComponent.js
hellcat 6adbc04d4b 1
2025-10-03 17:17:08 +08:00

21 lines
711 B
JavaScript

import { camelize, capitalize, getCurrentInstance } from 'vue';
/**
* Check if a global component with the given name exists
*
* 检查给定名称的全局组件是否存在
*
* @param name - Component name / 组件名称
* @param app - Vue app instance / Vue 应用实例
*
* @returns Whether the global component exists / 全局组件是否存在
*/
export const hasGlobalComponent = (name, app) => {
const globalComponents = (app?._instance ?? getCurrentInstance())?.appContext
.components;
if (!globalComponents)
return false;
return (name in globalComponents ||
camelize(name) in globalComponents ||
capitalize(camelize(name)) in globalComponents);
};