webpack vue 读取文件中的vue 文件
直接上代码:
// 获取组件下gallery 文件夹下的 .vue 文件
const files = require.context('@/components/gallery/', true, /\.vue$/);
// 空对象接收gallery
const gallery = {};
files.keys().forEach(key => {
curGallery[key.replace(/(\.\/|\.vue)/g, '')] = files(key).default;
})

当前keys 转数组
this.gallery= Object.keys(curGallery)

当前values转数组获取对象值
this.gallery= Object.values(curGallery)
tiryLi