vue-lazyload icon indicating copy to clipboard operation
vue-lazyload copied to clipboard

how to use vue-lazyload with sort or filter function

Open pdt590 opened this issue 6 years ago • 6 comments

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.

pdt590 avatar Jan 03 '19 15:01 pdt590

having the same problem here

eytanchen avatar Jan 06 '19 17:01 eytanchen

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

huangjinqiang avatar Jan 10 '19 01:01 huangjinqiang

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

RaphaelDDL avatar Feb 28 '19 19:02 RaphaelDDL

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

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

ghost avatar May 24 '19 03:05 ghost

this option works! observer: true

vonlyinno avatar Jan 06 '20 04:01 vonlyinno

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

tylik1 avatar Jan 08 '21 14:01 tylik1