网站首页 > 教程文章 正文
介绍
vue-lazyload是一个基于Vue的延迟加载插件,用于延迟加载Vue组件或者图像。
Github
https://github.com/hilongjw/vue-lazyload
特点
- 轻便,功能强大且易于使用
- 处理任何图像类型
- 加载图像时添加加载类
- 同时支持Vue 1.0和Vue 2.0
快速开始
npm i vue-lazyload -S
<script src="https://unpkg.com/vue-lazyload/vue-lazyload.js"></script>
<script>
Vue.use(VueLazyload)
...
</script>
使用
- main.js
import Vue from 'vue'
import App from './App.vue'
import VueLazyload from 'vue-lazyload'
Vue.use(VueLazyload)
// or with options
Vue.use(VueLazyload, {
preLoad: 1.3,
error: 'dist/error.png',
loading: 'dist/loading.gif',
attempt: 1
})
new Vue({
el: 'body',
components: {
App
}
})
- template
<ul>
<li v-for="img in list">
<img v-lazy="img.src" >
</li>
</ul>
- v-lazy-container使用原始HTML
<div v-lazy-container="{ selector: 'img' }">
<img data-src="//domain.com/img1.jpg">
<img data-src="//domain.com/img2.jpg">
<img data-src="//domain.com/img3.jpg">
</div>
- 自定义错误和加载占位符图像
<div v-lazy-container="{ selector: 'img', error: 'xxx.jpg', loading: 'xxx.jpg' }">
<img data-src="//domain.com/img1.jpg">
<img data-src="//domain.com/img2.jpg">
<img data-src="//domain.com/img3.jpg">
</div>
<div v-lazy-container="{ selector: 'img' }">
<img data-src="//domain.com/img1.jpg" data-error="xxx.jpg">
<img data-src="//domain.com/img2.jpg" data-loading="xxx.jpg">
<img data-src="//domain.com/img3.jpg">
</div>
- 配置
总结
具体详细的使用参考Github上的文档,vue-lazyload非常适合用在图片加在较多的网页上,效果优雅!
猜你喜欢
- 2025-05-24 在vue3中动态加载远程组件
- 2025-05-24 Motion for Vue:为Vue量身定制的强大动画库
- 2025-05-24 前端流行框架Vue3教程:14. 组件传递Props效验
- 2025-05-24 高性能 vue.js+ztree 树形组件Vue-GiantTree
- 2025-05-24 vue浏览器不可不看的宝藏插件
- 2025-05-24 重磅推荐:一个基于 Vue 的 (大转盘/九宫格) 抽奖插件
- 2025-05-24 Vue父子组件,利用条件延迟创建子组件,达到参数传递目的
- 2025-05-24 最近很火的Vue Vine是如何实现一个文件中写多个组件
- 2025-05-24 VUE - 如何写一个简易版 vue-router 插件
- 2025-05-24 超好用 Vue.js 图片裁切组件Vue-ImgCutter
- 05-25干货 | 一步步部署 Flask 应用
- 05-25别再去找Docker命令了,你要的常用的全都在这
- 05-25如果您删除Windows11上的“Program Files”文件夹会发生什么?
- 05-25家用nas最常用的docker容器及部署方法
- 05-25你好 dotnet run file, 再见 csproj
- 05-25China committed to continuing contributions to global health: delegation
- 05-25Chinese, German experts urge cooperation during Eurasia relations seminar
- 05-25Peace of paramount importance for region
- 最近发表
-
- 干货 | 一步步部署 Flask 应用
- 别再去找Docker命令了,你要的常用的全都在这
- 如果您删除Windows11上的“Program Files”文件夹会发生什么?
- 家用nas最常用的docker容器及部署方法
- 你好 dotnet run file, 再见 csproj
- China committed to continuing contributions to global health: delegation
- Chinese, German experts urge cooperation during Eurasia relations seminar
- Peace of paramount importance for region
- after和in用法解析
- China's top diplomat to chair third China-Pacific Island countries foreign ministers' meeting
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- mybatis plus page (35)
- vue @scroll (38)
- 堆栈区别 (33)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)
- redis aof rdb 区别 (33)
- 302跳转 (33)
- http method (35)
- js array splice (33)