引入某文件夹下的所有vue组件

const requireComps = require.context('文件夹路径', true, /\.vue$/);
const comps = {}
requireComps.keys().forEach(name => {
    const comp = requireComps(name).default // 要求vue组件的$option有name属性
    comps[comp.name] = comp // 注意此处comps和comp差别
})
export default {
    ...
    components: { ...comps }
    ...
}

Leave a Reply

Your email address will not be published. Required fields are marked *