hilongjw / vue-lazyload

A Vue.js plugin for lazyload your Image or Component in your application.
http://hilongjw.github.io/vue-lazyload/
MIT License
7.99k stars 865 forks source link

how to use vue-lazyload with sort or filter function #332

Open pdt590 opened 5 years ago

pdt590 commented 5 years ago

Hello I am using vue-lazyload for my shopping card project. vue-lazyload is used to display preview image in each item card. It runs well when every item cards are loaded at the first time. However, when i use my own sort or filter function to re-display the cards following orders such as newest oldest, the image in each card does not reload again to display correctly.

Do you have any solution for this? Thank you so much for your help.

eytanchen commented 5 years ago

having the same problem here

huangjinqiang commented 5 years ago

273

https://github.com/hilongjw/vue-lazyload/pull/301

RaphaelDDL commented 5 years ago

I have same issue, even after adding :key to the img as pointed on #273. The difference for me is that I'm not using v-lazy on the image, but using v-lazy-container.

I have the following:

    <div v-lazy-container="{ selector: '.hero-list-card-image, .artifact-list-card-image' }">
        <ListItemComponent :hero="hero" :id="hero.fileId" :key="hero.fileId" v-for="hero in displayHeroes" />

Inside ListItemComponent, I have the img:

           <img
                class="hero-list-card-image"
                :data-error="imageUrls.missing"
                :data-src="imageUrls.small"
                :key="`${hero.name}_small`"
            />

Which follows the suggested 273 approach by adding :key.

Nevertheless, whenever we do a filter on the computed property displayHeroes, just the first (sometimes the second) images show up.

image

The src was never set on the img: image

I tried to trigger a scroll to see if would make any change but no luck :P

const e = document.createEvent('Event');
e.initEvent('scroll', true, true);
window.dispatchEvent(e);

Any ideas? Should I create a new issue since I'm not using v-lazy but v-lazy-container?

btw, I changed the code to have v-lazy on the ListItemComponent and passing the object with src and error on the v-lazy and it worked. I guess v-lazy-container needs to have #301 ported to it

ghost commented 5 years ago

I got a solution. You need to add :key. Probably, it will work.

<img v-lazy="data.src" :key="data.src"/>

vonlyinno commented 4 years ago

this option works! observer: true

tylik1 commented 3 years ago

:key didn't work for me, while observer:true did. But scrolling became a bit slower