码迷,mamicode.com
首页 > 其他好文 > 详细

Vue图片懒加载插件 - vue lazyload的简单使用

时间:2018-09-03 15:06:35      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:save   ref   vue   script   png   html   div   imp   images   

Vue module for lazyloading images in your applications. Some of goals of this project worth noting include:

  1. Be lightweight, powerful and easy to use
  2. Work on any image type
  3. Add loading class while image is loading
  4. Supports both of Vue 1.0 and Vue 2.0

github地址: https://github.com/hilongjw/vue-lazyload

  1. 下载依赖

    npm install vue-lazyload --save
  2. 引入

    import Vue from 'vue'
    import App from '@/App'
    import VueLazyload from 'vue-lazyload'
  3. 配置

    Vue.use(VueLazyload, {
        error: 'dist/error.png', // 这个是请求失败后显示的图片
        loading: 'dist/loading.gif', // 这个是加载的loading过渡效果
        try: 2 // 这个是加载图片数量
    })
  4. 组件使用

    <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>

Vue图片懒加载插件 - vue lazyload的简单使用

标签:save   ref   vue   script   png   html   div   imp   images   

原文地址:https://www.cnblogs.com/liuyishi/p/9578200.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!