vue实现图片懒加载的方法分析

2020-06-16 06:44:29易采站长站整理

本文实例讲述了vue实现图片懒加载的方法。分享给大家供大家参考,具体如下:

vue图片懒加载使用

首先第一步,安装插件

vue-lazyload


npm install vue-lazyload --save-dev

在man.js中引入插件


import VueLazyLoad from 'vue-lazyload'

使用


Vue.use(VueLazyLoad,{
error:'', //加载失败的图
loading:'' //加载中的默认图
})

这是一个最简单的配置

官方的详细扩展配置文档

keydescriptiondefaultoptions
preLoad
proportion of pre-loading height(预加载高度比例)
1.3
Number
error
src of the image upon load fail(图片路径错误时加载图片)
'data-src'
String
loading
src of the image while loading(预加载图片)
'data-src'
String
attempt
attempts count(尝试加载图片数量)
3
Number
listenEvents

events that you want vue listen for

(想要监听的vue事件)

默认[‘scroll’]可以省略,

当插件跟页面中的动画或过渡等事件有冲突是,

可以尝试其他选项

['scroll'(默认),

'wheel',

'mousewheel',

'resize',

'animationend',

'transitionend',

'touchmove']

Desired Listen Events
adapter

dynamically modify the attribute of element

(动态修改元素属性)

{ }
Element Adapter
filter
the image’s listener filter(动态修改图片地址路径)