From 89b39916d77d410f931003f2cc645251cea0c87a Mon Sep 17 00:00:00 2001 From: aixianling Date: Fri, 19 Aug 2022 13:39:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E7=89=88=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E5=BA=93=E7=BB=84=E4=BB=B6=E6=95=B4=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/index.js | 28 ++++++++++++++++++++++++++++ examples/main.js | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 components/index.js diff --git a/components/index.js b/components/index.js new file mode 100644 index 00000000..32334ef7 --- /dev/null +++ b/components/index.js @@ -0,0 +1,28 @@ +//本地仓库外部组件 + +// 存储组件列表 +let components = []; +// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册 +const install = function (Vue) { + if (install.installed) return; + // 遍历注册全局组件 + let contexts = require.context('.', true, /[\\\/]Ai([^\\\/]+)\.vue$/); + if (contexts) { + contexts.keys().map((e) => { + components.push(contexts(e).default); + Vue.component(contexts(e).default.name, contexts(e).default); + }); + } +}; + +// 判断是否是直接引入文件 +if (typeof window !== 'undefined' && window.Vue) { + install(window.Vue); +} + +export default { + // 导出的对象必须具有 install,才能被 Vue.use() 方法安装 + install, + // 以下组件列表 + ...components +}; diff --git a/examples/main.js b/examples/main.js index 7dfe09af..a440cdd4 100644 --- a/examples/main.js +++ b/examples/main.js @@ -9,10 +9,12 @@ import 'dvcp-ui/lib/styles/common.scss'; import 'dvcp-ui/lib/dvcp-ui.css'; import store from './store'; import dataV from '@jiaminghi/data-view'; +import appComps from '../components' Vue.use(dataV); Vue.use(ui); Vue.use(vcUI); +Vue.use(appComps); //富文本编辑器配置 Vue.config.productionTip = false; Object.keys(utils).map((e) => (Vue.prototype[e] = utils[e]));