vue插件(批量注册公共组件..类似Vue.use(elementUI))

​
​
利用 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)

​

​

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值