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.galleryObject.keys(curGallery)

 当前values转数组获取对象值

this.gallery= Object.values(curGallery)

posted @ 2021-02-01 15:50  libenzheng  阅读(510)  评论(0)    收藏  举报