Vue.js dynamic images not working

I got this working by following code

  getImgUrl(pet) {
    var images = require.context('../assets/', false, /\.png$/)
    return images('./' + pet + ".png")
  }

and in HTML:

<div class="col-lg-2" v-for="pic in pics">
   <img :src="https://stackoverflow.com/questions/40491506/getImgUrl(pic)" v-bind:alt="pic">
</div>

But not sure why my earlier approach did not work.

Leave a Comment