Gathering detailed insights and metrics for lazy-load-vue3
Gathering detailed insights and metrics for lazy-load-vue3
Gathering detailed insights and metrics for lazy-load-vue3
Gathering detailed insights and metrics for lazy-load-vue3
npm install lazy-load-vue3
Typescript
Module System
Node Version
NPM Version
Vue (50.41%)
JavaScript (36.47%)
TypeScript (12.42%)
HTML (0.71%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
10 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Dec 26, 2023
Latest Version
2.0.1
Package Id
lazy-load-vue3@2.0.1
Unpacked Size
157.15 kB
Size
30.96 kB
File Count
37
NPM Version
9.5.1
Node Version
18.16.1
Published on
Aug 15, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
32
1$ npm i lazy-load-vue3 -S
main.js
1import {createApp} from 'vue' 2import LazyLoad from 'lazy-load-vue3' 3import App from './App.vue' 4 5const app = createApp(App) 6app.use(LazyLoad, {component: true}).mount('#app')
App.vue:
1 2<template> 3 <table> 4 <tr> 5 <td> 6 <img v-lazy="'https://v3.cn.vuejs.org/logo.png'"/> 7 <!-- or --> 8 <img v-lazy="{src: 'https://v3.cn.vuejs.org/logo.png', loadingClassList: ['loading']}"/> 9 </td> 10 </tr> 11 </table> 12</template>
key | description | default | type |
---|---|---|---|
src | The real image URL | - | string |
loadedClassList | List of class names for loaded state | - | string |
loading | The image URL of the loading and waitingLoad state | - | string |
loadingClassList | List of class names for loading and waitingLoad state | [] | string[] |
error | The image URL of the error state | - | string |
errorClassList | List of class names for error state | [] | string[] |
onError | Hook for image loading failure, the type DirectiveConfig is this element's config | - | function(el: HTMLElement, config: DirectiveConfig): void |
onLoad | Hook for image loading complete | - | function(el: HTMLElement, config: DirectiveConfig): void |
lazyKey | When there are multiple scrolling lists on the same page, set different values to differentiate. Otherwise, it may cause the update to fail | 'default' | string |
key | description | default | type |
---|---|---|---|
debounce | Is it necessary to actively trigger another monitoring (config. timeout+50) within a certain period of time after each scrolling (some special circumstances may cause individual elements in the view to be unable to trigger updates, such as the height of the loading component being higher than the height of the real component) | false | boolean |
afterListen | Hook that fires every time the listener completes | - | function(event: Event, lazyKeyElSetMap: Map<string, Set |
component | Whether to register the lazy component, If on, lazy-components can be used | false | boolean |
timeout | Throttling interval(unit:milliseconds) | 200 | number |
loadedClassList | Same as command, and the priority is lower than the Command Options | [] | string[] |
loading | Same as command and ditto | - | string |
loadingClassList | Same as command and ditto | [] | string[] |
error | Same as command and ditto | - | string |
errorClassList | Same as command and ditto | [] | string[] |
onError | Same as command and ditto | - | function |
onLoad | Same as command and ditto | - | function |
1 2<template> 3 <lazy-component> 4 <some-componet/> 5 </lazy-component> 6</template>
You can specify a loading slot to show when the element is waiting to load or is loading.
1 2<template> 3 <lazy-component> 4 <some-componet/> 5 <template #loading> 6 <span>loading...</span> 7 </template> 8 </lazy-component> 9</template>
You can also give lazy-component a lazyKey like a directive, it looks like this:
1 2<template> 3 <div class="container"> 4 <table> 5 <tr> 6 <td> 7 <lazy-component lazy-key="column1"> 8 <some-componet1/> 9 </lazy-component> 10 </td> 11 </tr> 12 <tr>...</tr> 13 <tr>...</tr> 14 <tr>...</tr> 15 <tr>...</tr> 16 </table> 17 18 <table> 19 <tr> 20 <td> 21 <img v-lazy="URL" lazy-key="column2"/> 22 </td> 23 <td> 24 <lazy-component lazy-key="column3"> 25 <some-componet2/> 26 </lazy-component> 27 </td> 28 </tr> 29 <tr>...</tr> 30 <tr>...</tr> 31 <tr>...</tr> 32 <tr>...</tr> 33 </table> 34 </div> 35</template>
The components have strong scalability, and you can define advanced functions yourself.
key | description | default | type |
---|---|---|---|
lazy-key | Same as command, and the priority is higher than the Installation Options | 'default' | string |
name | description |
---|---|
default | The real element or component to display |
loading | The element or component of the loading and waitingLoad state |
key | description | |
---|---|---|
config | The global configuration when registering the plugin, you can modify it later | |
listener | Listener to manually force a check to be triggered | |
default | Whole plugin |
As for listener, you can just call such as listener()
. You can pass a boolean value to the listener to specify whether your manual listener is checked in an ordered manner. This parameter will not
change the sorted order of the original config.
If there is an update exception, you can also call the listener to force sorting and update effectively, like this.
1import {listener} from 'lazy-load-vue3' 2 3listener(undefined, true)
Do not hide the target element and lazy component of the instruction.
unsafe:
1<template> 2 <table v-for="item of list"> 3 <tr> 4 <td> 5 <!-- Don't use like this. --> 6 <lazy-component v-show="item.show"> 7 <template #loading> 8 loading... 9 </template> 10 <div>{{item.content}}</div> 11 </lazy-component> 12 </td> 13 </tr> 14 </table> 15</template> 16 17<script setup lang="js"> 18 19const list = ref([]) 20for(let i = 0; i < 100; i++) { 21 list.value[i] = {show: i % 2 === 0, content: 'content' + i} 22} 23 24</script>
safe:
1 2<template> 3 <table v-for="item of list"> 4 <tr> 5 <td> 6 <lazy-component> 7 <template #loading> 8 loading... 9 </template> 10 <!-- Use like this. --> 11 <div v-show="item.show">{{item.content}}</div> 12 </lazy-component> 13 </td> 14 </tr> 15 </table> 16</template> 17 18<script setup lang="js"> 19 20const list = ref([]) 21for (let i = 0; i < 100; i++) { 22 list.value[i] = {show: i % 2 === 0, content: 'content' + i} 23} 24 25</script>
afterListen
hook change parameters.watchUpdate
option.afterListen
hook.No vulnerabilities found.
No security vulnerabilities found.