All Projects → murongg → vue3-lazyload

murongg / vue3-lazyload

Licence: other
A vue3.x image lazyload plugin

Programming Languages

typescript
32286 projects
Vue
7211 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to vue3-lazyload

vue3-analysis
vue3源码解释😃
Stars: ✭ 120 (+84.62%)
Mutual labels:  vue3
vite-svg
Use SVG files as Vue components with Vite
Stars: ✭ 98 (+50.77%)
Mutual labels:  vue3
vuestic-ui
Free and Open Source UI Library for Vue 3 🤘
Stars: ✭ 1,501 (+2209.23%)
Mutual labels:  vue3
vue-split-carousel
a carousel component for vue, meanwhile display several carousel item
Stars: ✭ 37 (-43.08%)
Mutual labels:  vue3
vite-primevue-starter
VUE 3 Starter project for using primevue 3 with Vite 2 - Pages, Layouts, Validation
Stars: ✭ 37 (-43.08%)
Mutual labels:  vue3
lsp-volar
Language support for Vue3
Stars: ✭ 20 (-69.23%)
Mutual labels:  vue3
portfolio
simple portfolio use vue3 and vite inspired by wrongakram
Stars: ✭ 22 (-66.15%)
Mutual labels:  vue3
GoWebSSH
功能强大,Go 实现的一个WebSSH,支持文件上传下载
Stars: ✭ 112 (+72.31%)
Mutual labels:  vue3
sonic-client-web
🎉Front end of Sonic cloud real machine testing platform. Sonic云真机测试平台前端。
Stars: ✭ 512 (+687.69%)
Mutual labels:  vue3
vite2-vue3-admin
Vite2 + Vue3.0 + ant-design 2.x
Stars: ✭ 28 (-56.92%)
Mutual labels:  vue3
admin-next
😇 The next generation of mx-space admin dashboard built with Vue 3 and TypeScript.
Stars: ✭ 71 (+9.23%)
Mutual labels:  vue3
vue-antd-admin
基于vue3.0 + vue-cli4.0 + vue-router4.x + vuex4.x + ant-design-vue2.x开发的后台管理系统模板,包含权限路由、权限按钮、流程配置、个人中心等基础功能
Stars: ✭ 57 (-12.31%)
Mutual labels:  vue3
vue-magnify
vue-magnify / vue放大镜组件
Stars: ✭ 14 (-78.46%)
Mutual labels:  vue3
ionic-vue-mobile-template-03
Hybrid app template built with vue, ionic and capacitor.
Stars: ✭ 62 (-4.62%)
Mutual labels:  vue3
vue3-datepicker
Simple datepicker component for Vue 3
Stars: ✭ 93 (+43.08%)
Mutual labels:  vue3
vite-vue3-starter
⭐ A Vite 2.x + Vue 3.x + TypeScript template starter
Stars: ✭ 384 (+490.77%)
Mutual labels:  vue3
admin-antd-vue
Vue3.x + Ant Design Admin template (vite/webpack)
Stars: ✭ 111 (+70.77%)
Mutual labels:  vue3
vue3-form-validation
Vue Composition Function for Form Validation
Stars: ✭ 18 (-72.31%)
Mutual labels:  vue3
vitesome
A simple opinionated Vue3 Starter Template with Vite.js
Stars: ✭ 124 (+90.77%)
Mutual labels:  vue3
templates
tsParticles website templates collection
Stars: ✭ 42 (-35.38%)
Mutual labels:  vue3

vue3-lazyload



A vue3.x image lazyload plugin.

🚀 Features

  • 0 dependencies: No worry about your bundle size
  • 🦾 Type Strong: Written in Typescript
  • 🌎 Browser support: Use it through CDN
  • 😊 Support Hook: useLazyload

📎 Installation

$ npm i vue3-lazyload
# or
$ yarn add vue3-lazyload

🌎 CDN

CDN: https://unpkg.com/vue3-lazyload

<script src="https://unpkg.com/vue3-lazyload"></script>
<script>
  Vue.createApp(App).use(VueLazyLoad)
  ...
</script>

👽 Usage

main.js:

import { createApp } from 'vue'
import VueLazyLoad from 'vue3-lazyload'
import App from './App.vue'

const app = createApp(App)
app.use(VueLazyLoad, {
  // options...
})
app.mount('#app')

App.vue:

<template>
  <img v-lazy="your image url" />
</template>

v-lazy use object params

<template>
  <img v-lazy="{ src: 'your image url', loading: 'your loading image url', error: 'your error image url' }">
</template>

Use lifecycle

In main.js

import { createApp } from 'vue'
import VueLazyLoad from 'vue3-lazyload'
import App from './App.vue'

const app = createApp(App)
app.use(VueLazyLoad, {
  loading: '',
  error: '',
  lifecycle: {
    loading: (el) => {
      console.log('loading', el)
    },
    error: (el) => {
      console.log('error', el)
    },
    loaded: (el) => {
      console.log('loaded', el)
    }
  }
})
app.mount('#app')

or

In xxx.vue

Have to be aware of is v-lazy don't use v-lazy="lazyOptions", in this case, vue cannot monitor data changes.

<script>
import { reactive } from 'vue'
export default {
  name: 'App',
  setup() {
    const lazyOptions = reactive({
      src: 'your image url',
      lifecycle: {
        loading: (el) => {
          console.log('image loading', el)
        },
        error: (el) => {
          console.log('image error', el)
        },
        loaded: (el) => {
          console.log('image loaded', el)
        }
      }
    })
    return {
      lazyOptions,
    }
  }
}
</script>

<template>
  <img v-lazy="{src: lazyOptions.src, lifecycle: lazyOptions.lifecycle}" width="100">
</template>

Use Hook

<script lang="ts">
import { ref } from 'vue'
import { useLazyload } from 'vue3-lazyload'
export default {
  name: 'App',
  setup() {
    const src = ref('/example/assets/logo.png')
    const lazyRef = useLazyload(src, {
      lifecycle: {
        loading: () => {
          console.log('loading')
        },
        error: () => {
          console.log('error')
        },
        loaded: () => {
          console.log('loaded')
        }
      }
    })
    return {
      lazyRef
    }
  }
}
</script>

<template>
  <img ref="lazyRef" class="image" width="100">
</template>

Use css state

There are three states while image loading.
You can take advantage of this feature, make different css controls for different states.

  • loading
  • loaded
  • error
<img src="..." lazy="loading">
<img src="..." lazy="loaded">
<img src="..." lazy="error">
<style>
  img[lazy=loading] {
    /*your style here*/
  }
  img[lazy=error] {
    /*your style here*/
  }
  img[lazy=loaded] {
    /*your style here*/
  }
</style>

Delay loading of images

To avoid loading images that are only shortly visible (e. g. fast scrolling through list of images), a delay in milliseconds can be configured. If a delay is set, an image is only loaded if it stays visible for the specified amount of time.

Set delay in object parameter:

<template>
  <img v-lazy="{ src: 'your image url', loading: 'your loading image url', error: 'your error image url', delay: 500 }">
</template>

📁 Options

key description default type
loading The image used when the image is loaded - string
error The image used when the image failed to load - string
observerOptions IntersectionObserver options { rootMargin: '0px', threshold: 0.1 } IntersectionObserverInit
log Do not print debug info true boolean
lifecycle Specify state execution function - Lifecycle
delay Time in milliseconds an image has to stay visible before loading starts 0 number

Lifecycle Hooks

key description
loading Image loading
loaded Image loaded
error Image load error

📄 TODO

  • Migrate to typescript
  • rollup
  • eslint
  • overall unit tests
  • *.d.ts
  • Perfect type
  • lifecycle
  • commitlint & husky
  • LazyComponent
  • LazyImage
  • LazyContainer
  • Perfect example

Contributors

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].