Skip to content

Lazyload - Vant 4

Lazyload

🚀 Boost your app's performance with intelligent lazy loading that delivers lightning-fast user experiences!

📖 Intro

Transform your app's performance with smart lazy loading! When your page contains heavy content, Lazyload intelligently defers loading images and components until they're actually needed, creating buttery-smooth scrolling experiences and dramatically reducing initial load times.

📦 Install

Get started in seconds! Register Lazyload globally via app.use and unlock powerful performance optimizations. Check out our Component Registration guide for additional setup options.

js
import { createApp } from'vue'; import { Lazyload } from'vant'; const app = createApp(); app.use(Lazyload); // with options app.use(Lazyload, { lazyComponent: true, });

🎨 Usage

Discover the power of intelligent loading with these practical examples

🌟 Basic Usage

html
js
exportdefault { setup() { return { imageList: [ 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', ], }; }, };

🖼️ Lazyload Background Image

Create stunning visual experiences with lazy-loaded backgrounds! Use v-lazy:background-image to efficiently load background images while maintaining smooth scrolling. Remember to declare the container height for optimal rendering.

html

🧩 Lazyload Component

Take lazy loading to the next level with component-level optimization! Enable component lazy loading to defer entire Vue components until they enter the viewport, perfect for heavy widgets and complex UI sections.

js
// set `lazyComponent` option app.use(Lazyload, { lazyComponent: true, });
html

🔧 API

Fine-tune your lazy loading experience with powerful configuration options

🎛️ Options

Customize every aspect of lazy loading behavior to match your app's specific needs

AttributeDescriptionTypeDefault
loadingSrc of the image while loadingstring-
errorSrc of the image upon load failstring-
preLoadProportion of pre-loading heightnumber-
attemptAttempts countnumber3
listenEventsEvents that you want vue listen forstring[]scroll...
adapterDynamically modify the attribute of elementobject-
filterThe image's listener filterobject-
lazyComponentLazyload componentbooleanfalse

See more: vue-lazyload

Explore related components and features to enhance your development experience

Enterprise-level mobile solution based on Vant