vue2导入所有的自定义组件
import Vue from 'vue' const requireComponent = require.context('./', true, /index.vue$/) requireComponent.keys().forEach(filePath => { const componentConfig = requireComponent(filePath) const componentName = filePath.replace(/.\/(\w+)\/(\w+).vue/, '$1') Vue.component(componentName, componentConfig.default || componentConfig) }, {})
然后在main.js引入该文件就行了