1

I have an image changes in the server but without changing the name so I want to reload the source in vuejs without refreshing the page, This my vue :

<template>
    <div class="container">
        <img src="http://localhost:8082/files/file.jpeg">
    </div>
</template>
<script>
</script>

1 Answers1

0

When you change the src the image will reload. you can keep the source as is but add a cache key to the src.

<template>
    <div class="container">
        <img 
          :src=`${imageURL}?cache=${cacheKey}`>
    </div>
</template>

and in your script add the following:

data() {
 return {
      cacheKey: 1,
      imageURL: 'http://localhost:8082/files/file.jpeg'  
 }
}
updateImgMethod(){
 const nowTime = +new Date()
 this.cacheKey = nowTime
}
Tawfik Nasser
  • 1,018
  • 9
  • 17