本文实例讲述了vue实现图片懒加载的方法。分享给大家供大家参考,具体如下:
vue图片懒加载使用
首先第一步,安装插件
vue-lazyload
npm install vue-lazyload --save-dev在man.js中引入插件
import VueLazyLoad from 'vue-lazyload'使用
Vue.use(VueLazyLoad,{
error:'', //加载失败的图
loading:'' //加载中的默认图
})这是一个最简单的配置
官方的详细扩展配置文档
| key | description | default | options |
|---|---|---|---|
| proportion of pre-loading height(预加载高度比例) |
|
|
| src of the image upon load fail(图片路径错误时加载图片) |
|
|
| src of the image while loading(预加载图片) |
|
|
| attempts count(尝试加载图片数量) |
|
|
| events that you want vue listen for (想要监听的vue事件) 默认[‘scroll’]可以省略, 当插件跟页面中的动画或过渡等事件有冲突是, 可以尝试其他选项 |
| Desired Listen Events |
| dynamically modify the attribute of element (动态修改元素属性) |
| Element Adapter |
| the image’s listener filter(动态修改图片地址路径) |










