vue-lazyload簡單使用html
npm地址:https://www.npmjs.com/package/vue-lazyloadvue
github地址:https://github.com/hilongjw/vue-lazyloadgit
例子:http://hilongjw.github.io/vue-lazyload/
1安裝插件github
npm install vue-lazyload --save
或者CDN: https://unpkg.com/vue-lazyload/vue-lazyload.jsnpm
<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 } })
<ul> <li v-for="img in list"> <img v-lazy="img.src" > </li> </ul>