Dynamically get image paths in folder with Nuxt

后端 未结 1 1956
野性不改
野性不改 2021-01-04 23:53

I\'m using nuxt with vuetify. I have a working carousel component .I want to generate a list of The .png files in the static folder. Following Dynamically import im

相关标签:
1条回答
  • 2021-01-05 00:22

    The following appears to work:

    <template>
      <v-carousel>
        <v-carousel-item v-for="(item,i) in items" :key="i" :src="item.src"></v-carousel-item>
      </v-carousel>
    </template>
    
    
    <script>
      var cache = {};
      const images = require.context('../static/', false, /\.png$/);
      var imagesArray = Array.from(images.keys());
      var constructed = [];
      function constructItems(fileNames, constructed) {
        fileNames.forEach(fileName => {
          constructed.push({
            'src': fileName.substr(1)
          })
        });
        return constructed;
      }
      var res = constructItems(imagesArray, constructed);
      console.log(res);
      export default {
        data: function() {
          return {
            items: res
          };
        }
      };
    

    0 讨论(0)
提交回复
热议问题