vue-lazyload简单使用

vue-lazyload简单使用

npm地址:https://www.npmjs.com/package/vue-lazyload

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

例子:http://hilongjw.github.io/vue-lazyload/
1安装插件

npm install vue-lazyload   --save

或者CDN: https://unpkg.com/vue-lazyload/vue-lazyload.js

<script src="https://unpkg.com/vue-lazyload/vue-lazyload.js"></script>
<script>
  Vue.use(VueLazyload)
  ...
</script>

2.引用文件,一般在main.js全局引用,且配置好图片

//main.js
import Vue from 'vue'
import App from './App.vue'
import VueLazyload from 'vue-lazyload'
 
Vue.use(VueLazyload)
 
// or with options
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: 'dist/error.png',
  loading: 'dist/loading.gif',
  attempt: 1
})
 
new Vue({
  el: 'body',
  components: {
    App
  }
})
  1. vue文件中将需要懒加载的图片绑定 v-bind:src 修改为 v-lazy
<ul>
  <li v-for="img in list">
    <img v-lazy="img.src" >
  </li>
</ul>

博客看自:https://www.cnblogs.com/zzxuan/p/9690496.html

posted @ 2019-07-11 10:15  jser_dimple  阅读(380)  评论(0编辑  收藏  举报
/*function gotourl() { var url = "https://www.cnblogs.com/smart-girl/"; var localurl = document.url; if( localurl.substring(0,url.length) != url ) { location.href=url; } } gotourl();*/