- 一般我们注册组件都在入口文件main.js中 使用Vue.component(组件名,组件)注册
弊端 :
-
如果组件过多无法保持main.js文件的简洁
解决方法 : 抽离组件注册
1.在公共组件component中新建index.js
2. 在main.js文件中引入
3.这样就可以在component 中注册多个组件了
二 . 使用Vue.use() 注册组件
- 了解 Vue.use()
- 在main.js中引入 index.js文件 使用 Vue.use() 将文件以参数传入
-
注册全局组件 使用 install(vue) 注册组件
-
Vue.use() 实现原理
- 需要传入一个参数对象||函数
- 如果参数是对象提供了 install()函数
- install() 函数接收的参数是 Vue
- 使用 Vue.component() 注册
-