欢迎来到码农权的博客 MaNongGeGe.|

vue3自定义组件全局注入

/**
 * 自定义组件全局注入
 * @param app vue实例
 */
import { defineAsyncComponent } from "vue";
export default function (app) {
    // 收集@/components所有.vue组件
    const components = import.meta.glob('@/components/*/*.vue');
    for(let [key, value] of Object.entries(components)) {
        let _Name = key.split('/');
        _Name = _Name[_Name.length - 1].replace(/\.vue$/, "");
        // 生成组件的名字
        const componentName = `XiaoQuan-${_Name}`;
        // 注入
        app.component(componentName, defineAsyncComponent(value));
    }
}

本文作者:HuangBingQuan

本文链接:https://www.cnblogs.com/bingquan1/p/17898007.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   HuangBingQuan  阅读(88)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 不将就 码农权
  2. 2 Bleeding Love 码农权
  3. 3 想你念你 码农权
Bleeding Love - 码农权
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available