const resultComps = {};
let requireComponent = require.context(
'./', // 在当前目录下查找
true, //false 不遍历子文件夹 true 遍历子文件夹
/\.vue$/ // 正则匹配 以 .vue结尾的文件
)
requireComponent.keys().forEach(fileName => {
// 组件实例
const reqCom = requireComponent(fileName)
resultComps[fileName.replace(/^\.\/(.*)\.\w+$/, '$1')] = reqCom.default
})
export default resultComps
标签:vue,匹配,requireComponent,fileName,reqCom,resultComps,组件 From: https://www.cnblogs.com/mrt-yyy/p/17086153.html