Answers for "image src in vue js"

0

vue dynamic image src

<template>
   <div v-for="pic in pics">
      <img :src="getImgUrl(pic)" v-bind:alt="pic">
   </div>
</template>

<script>
  getImgUrl(pet) {
    var images = require.context('../assets/', false, /\.png$/)
    return images('./' + pet + ".png")
  }
</script>
Posted by: Guest on October-09-2021
0

vue image src

<img v-bind:src="'/media/avatars/' + joke.avatar" />
Posted by: Guest on April-27-2021
0

render image in vue

<template>
  <div>
    <img :src="image"/>
  </div>
</template>
<script>
export default {
  mounted: function() {
    if (this.source) { //is it empty
      this.image = this.source //replace placeholder
    }
   this.loading = false
  },
  data () {
    return {
      image: somePlaceholderImage,//url for placeholder image
      loading: true
    }
  },
  props: ['source'],
}
</script>

<style>

</style>
Posted by: Guest on July-05-2021

Browse Popular Code Answers by Language