31 lines
		
	
	
		
			843 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			843 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const apps = []
 | ||
| const install = function (Vue) {
 | ||
|   if (install.installed) return Promise.resolve()
 | ||
|   else {
 | ||
|     let contexts = require.context('.', true, /(\/.+)\/Ai[^\/]+\.vue$/)
 | ||
|     if (contexts) {
 | ||
|       contexts.keys().map(e => {
 | ||
|         if (contexts(e).default) {
 | ||
|           let mod = apps.find(a => a.name == contexts(e).default.name)
 | ||
|           if (mod) {
 | ||
|             mod.component = contexts(e).default
 | ||
|           } else {
 | ||
|             apps.push({name: contexts(e).default.name, component: contexts(e).default})
 | ||
|           }
 | ||
|         }
 | ||
|       })
 | ||
|     }
 | ||
|     apps.map(e => {
 | ||
|       Vue.component(e.name, e.component)
 | ||
|     })
 | ||
|   }
 | ||
| }
 | ||
| // 判断是否是直接引入文件
 | ||
| if (typeof window !== 'undefined' && window.Vue) {
 | ||
|   install(window.Vue)
 | ||
| }
 | ||
| export default {
 | ||
|   // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
 | ||
|   install
 | ||
| }
 |