Create a custom directive (e.g., for lazy loading images).

Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
<template>
  <img v-lazy-load="'image-url.jpg'" />
</template>

<script setup>
const vLazyLoad = {
  mounted: (el, binding) => {
    const observer = new IntersectionObserver(entries => {
      if (entries[0].isIntersecting) {
        el.src = binding.value;
        observer.unobserve(el);
      }
    });
    observer.observe(el);
  }
};
</script>