使用Vue-Lazyload图片进行懒加载

1.引入

npm i --save vue-lazyload

2.使用

  • main.js:
import Vue from 'vue'
import App from './App.vue'
import VueLazyload from 'vue-lazyload'

//引入图片未加载出来之前要加载的图片
import loading from './common/images/loading.gif'

Vue.use(VueLazyload)

// or with options
Vue.use(VueLazyload, {
 loading
})

new Vue({
  el: 'app',
  components: {
    App
  }
})
  • template:
<ul>
  <li v-for="img in list">
    <img v-lazy="图片路径" >
  </li>
</ul>    

3.参数选项说明

key description default options
preLoadproportion of pre-loading height1.3Number
error当加载图片失败的时候'data-src'String
loading当加载图片成功的时候'data-src'String
attempt尝试计数3Number
listenEvents想要监听的事件['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend', 'touchmove']Desired Listen Events
adapter动态修改元素属性{ }Element Adapter
filter图片监听或过滤器{ }Image listener filter
lazyComponentlazyload componentfalseLazy Component
dispatchEvent触发dom事件falseBoolean
throttleWaitthrottle wait200Number
observeruse IntersectionObserverfalseBoolean
observerOptionsIntersectionObserver options{ rootMargin: '0px', threshold: 0.1 }IntersectionObserver
posted @ 2019-08-20 22:17  麦田的老哥  阅读(7)  评论(0)    收藏  举报