surprise
2024-02-02 0d02f863ebd8193ea6f6b0f363620bba6894134a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 导入组件
import Chat from './Chat'
import ChatPage from './ChatInterface'
import Icon from './Icon'
import UserItem from './UserItem'
import Empty from './Empty'
import RightList from './RightList'
import QuickTalk from './QuickTalk'
import Count from './Count'
import UserCard from './UserCard'
 
// 以数组结构保存组件,便于遍历
const components = [
  Chat,
  ChatPage,
  Icon,
  UserItem,
  Empty,
  RightList,
  QuickTalk,
  Count,
  UserCard
]
 
// 定义 install 方法
const install = function (Vue) {
  if (install.installed) return
  install.installed = true
 
  // 遍历并注册全局组件
  components.map(component => {
    Vue.component(component.name, component)
  })
}
 
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}
 
export default {
  // 导出的对象必须具备一个 install 方法
  install,
  // 组件列表
  ...components
}