I need help figuring out how to properly set up lazy loading for images coming from Airtable using Vue.js.
I’m building a website that pulls image data from my Airtable database and displays it using Vue. Right now I have this code that works fine for showing images:
The problem is that I added a lazy loading library but it’s not working at all. All the images still load right when the page opens instead of waiting until they’re needed. I think the issue is that I need to use ‘data-src’ instead of ‘:src’ for the lazy loading to work properly.
Deal with this constantly at work. Your lazy loading library gets confused when images show up after the initial DOM scan.
I use a watcher to reinitialize the lazy loader whenever Airtable data changes:
watch: {
records: {
handler() {
this.$nextTick(() => {
// Force lazy loader to rescan for new images
if (window.lazySizes) window.lazySizes.autoSizer.checkElems();
// Or whatever method your library uses
});
},
deep: true
}
}
For HTML, use regular data-src without Vue binding:
Watcher fires every time Airtable data updates and tells the lazy loader to scan for new images. Way more reliable than timing it manually after API calls.
Which lazy loading library are you using? The rescan method name varies.
Classic issue - your lazy loading library loads before the Airtable data shows up. I’ve hit this exact problem with dynamic content from external APIs. Most lazy loading libraries only scan for images once when they initialize. Since your Airtable images aren’t in the DOM yet, they never get registered.
I stopped fighting with data-src binding and handled lazy loading directly in Vue instead:
Then I used an intersection observer or scroll listener in the Vue component to flip shouldLoad to true when needed. You get full control over when images load without depending on external libraries that weren’t built for dynamic Vue content. Same performance boost, but no timing or DOM binding headaches.
yeah, same thing happened to me. use the v-lazy-image directive instead of mixing Vue with regular lazy loading libraries - most of those don’t play well with Vue’s rendering cycle. or do a quick manual check: drop a console.log right after your airtable data loads to see if the img elements are actually in the DOM when the lazy loader runs. i bet they’re not.
Had the same issue mixing lazy loading with external API content. The problem is lazy loading libraries scan the DOM once during setup, but your Airtable images get added later when Vue updates.
This fixed it for me - use v-bind without the colon for data-src:
This way the attribute gets set as regular HTML instead of going through Vue’s reactivity.
You also need to call your lazy loading library’s observer or refresh method after the Airtable data loads. Most have something like observer.observe() or refresh() that you can trigger in your .then() block. Skip this and the library won’t see your new images.