diff --git a/client/src/icons/index.ts b/client/src/icons/index.ts index 3ae6e10..e4cd5fc 100644 --- a/client/src/icons/index.ts +++ b/client/src/icons/index.ts @@ -1,21 +1,15 @@ -// 从项目路径 '@/components/SvgIcon/index.vue' 导入 SvgIcon 组件 import SvgIcon from '@/components/SvgIcon/index.vue' -// 从 'vue' 中导入 App 类型,用于表示 Vue 应用实例 import { App } from 'vue' // 获取上下文 require.context(检索的目录,是否检索子文件夹,正则表达式) // 返回值是一个函数(传入路径可以导入文件) // 通过静态方法keys可以检索所有文件路径 // 通过.prototype可以查看所有静态方法 -// 这里指定检索当前目录下的 './svg' 文件夹,不检索子文件夹,匹配所有以.svg 结尾的文件 + const svgRequired = require.context('./svg', false, /\.svg$/) -// 遍历所有匹配的 SVG 文件路径 svgRequired.keys().forEach(item => svgRequired(item)) -// 导出一个默认函数,该函数接收一个 Vue 应用实例 app 作为参数 export default (app: App) => { - // 使用 app.component 方法将 SvgIcon 组件注册为全局组件,别名为'svg-icon' - // 这样在整个 Vue 应用中都可以使用 标签来使用该组件 app.component('svg-icon', SvgIcon) }