likes
comments
collection
share

vue2通用组件一次性注册

作者站长头像
站长
· 阅读数 280

代码

// 在main.js
// 通用组件地址: src/components/base
const files = require.context('./components/base, true', /\.vue$/)
const components = {}
files.keys().forEach(key => {
  components[key.replace(/(\.\/|\.vue)/g, '')] = files(key).default
})

Object.keys(components).forEach(key => {
  Vue.component(key, components[key])
})

使用

// 在想要用的组件内只用写通用组件标签即可
<base-title />