利用 Vue.use 统一全局注册组件
说明:
1. Vue.use 可以接收一个对象, Vue.use(obj)
2. 对象中需要提供一个 install 函数
3. install 函数可以拿到参数 Vue, 且将来会在 Vue.use 时, 自动调用该 install 函数
//src/componets/index.js
// 该文件负责所有的公共组件的全局注册
// vue插件机制: Vue.use
import PageTools from '@/components/PageTools'
const components = [
PageTools
]
export default {
install(Vue) {
components.forEach(item => {
Vue.component(item.name, item)
})
}
}
在入口处进行注册 src/main.js Vue.use 注册使用自己的插件模块
import Components from './components'
Vue.use(Components)
vue插件(批量注册公共组件..类似Vue.use(elementUI))
于 2023-10-26 23:18:38 首次发布