I have code that retrieves a list of images as an object, e.g.
[
{ src: '/path/to/img.jpg', loaded: false },
...
]
and a template that then displays them as HTML, for example:
<div
v-for="image in alltheimages"
:key="image.id" >
<transition name="fade" appear>
<img
:src="image.src"
v-show="image.loaded"
@load="image.loaded = true"
/>
</transition>
</div>
This works well on the first page load; images disappear as soon as they are loaded.
However, a problem arises when the image is already loaded into the cache , because then it @loadnever works on a new element <img>. In these situations, I can check the DOM img tag property .complete, but how can I do this in VueJS?
I tried v-show="this.complete || image.loaded", but thisjust points to window. I thought I could use a method call and pass a reference to the element that initiated the call, but I cannot find out how to do this.
, new Image(), listenter load, src, , , , - DOM, Vue.