Monday, 22 February 2021

Bind this for load event in v-for template

Is there a way to bind a given data prop in template while looping over array?

<div v-for="(page, pageIndex) in pages" :key="pageIndex">
    <img 
        :src="" 
        @load="onImageLoaded.bind(this, someDataVar)" 
    />
</div>

So if in the meantime (until the image gets loaded) someDataVar will gonna be changed, I still want to output in onImageLoaded the original value of someDataVar at the time the image was added to DOM by the for-loop.

PS: I've tried with IIFE but it didn't worked



from Bind this for load event in v-for template

No comments:

Post a Comment