Vue图片懒加载插件 - vue lazyload的简单使用
2024-10-09 21:57:30
Vue module for lazyloading images in your applications. Some of goals of this project worth noting include:
- Be lightweight, powerful and easy to use
- Work on any image type
- Add loading class while image is loading
- Supports both of Vue 1.0 and Vue 2.0
github地址: https://github.com/hilongjw/vue-lazyload
下载依赖
npm install vue-lazyload --save
引入
import Vue from 'vue'
import App from '@/App'
import VueLazyload from 'vue-lazyload'
配置
Vue.use(VueLazyload, {
error: 'dist/error.png', // 这个是请求失败后显示的图片
loading: 'dist/loading.gif', // 这个是加载的loading过渡效果
try: 2 // 这个是加载图片数量
})
组件使用
<template>
<div class="lazyLoad">
<ul id="container">
<li v-for="img in arr">
<img v-lazy="img.thumbnail_pic_s">
</li>
</ul>
</div>
</template> <script>
export default({
name:"lazyLoad",
data(){
return{
arr:[]
}
},
mounted:function(){
this.$http.get('/api/data').then(res=>{
this.arr=res.data.data;
console.log(this.data)
})
},
})
</script> <style scoped>
li{
list-style: none
}
</style>
如果需求中是, 不同的组件中默认的loading图不同. 可如下配置
v-lazy:background-image="{src: item.src, error: 'http://domain.com/error.png', loading: 'http://domain.com/loading-spin.svg'}"
最新文章
- php 去掉字符串的最后一个字符
- LVM逻辑卷管理
- codeforces 711A A. Bus to Udayland(水题)
- NEFU 1142 表哥的面包
- java mvc控制器基本传值方式
- nginx linux 下开机自动启动
- Spark机器学习 Day1 机器学习概述
- 5个最优秀的Java和C#代码转换工具
- spring beans源码解读
- Mac苹果电脑加密视频播放器使用教程
- CSS 伪元素
- 怎样在android实现uc和墨迹天气那样的左右拖动效果
- 脱O把妹,记录这一周来迁移至MySQL的一些心得
- Android系统--输入系统(十五)实战_使用GlobalKey一键启动程序
- 关于mule中使用jdbc时报No Suitable Driver found错误的问题
- java中,用json格式转换遇到问题
- vue 格式化银行卡(信用卡)每4位一个符号隔断
- .net core 2.x - 缓存的四种方式
- sybase解决死锁
- cdh启动datanode报错