vue-lazyload圖片延遲加載插件的實例講解
更新時間:2018年02月09日 09:24:27 作者:longzhoufeng
下面小編就為大家分享一篇vue-lazyload圖片延遲加載插件的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
1、首先在npm上下載vue-lazyload的引用包
npm install vue-lazyload --save-dev
2、然后我們在main.js里面import這個包,當然,單單這一個包是不夠的,還得其他的文件
import Vue from 'vue'; import App from './App.vue' import router from './router'; import VueLazyload from "vue-lazyload"
3、然后我們配置vue-lazyload
Vue.use(VueLazyload, {
error: 'static/error.png',//這個是請求失敗后顯示的圖片
loading: 'static/loading.gif',//這個是加載的loading過渡效果
try: 2 // 這個是加載圖片數(shù)量
})
4、具體配置api可以看下圖

html
<template>
<div>
<ul id="container">
<li v-for="img in list">
<img v-lazy="img">
</li>
</ul>
</div>
</template>
JS
<script>
export default {
data () {
return {
list: [
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
'http://st2.depositphotos.com/thumbs/2627021/image/9638/96385166/api_thumb_450.jpg!thumb',
]
}
}
}
</script>
css
<style>
//圖片加載中...
img[lazy=loading] {
/*width: 100px;*/
background-position:center center!important;
background: url("../../../static/images/loading.gif");
background-size:100px 100px;
background-repeat:no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
img[lazy=error] {
/*width: 100px;*/
background-position:center center!important;
background: url("../../../static/images/error.png");
background-size:100px 100px;
background-repeat:no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
img[lazy=loaded] {
/*width: 100px;*/
background-position:center center!important;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-color: green;
}
/*
or background-image
*/
.yourclass[lazy=loading] {
/*your style here*/
}
.yourclass[lazy=error] {
/*your style here*/
}
.yourclass[lazy=loaded] {
/*your style here*/
}
</style>
以上這篇vue-lazyload圖片延遲加載插件的實例講解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue+Java后端進行調(diào)試時解決跨域問題的方式
今天在開發(fā)中遇到有點小問題,vue+Java后端進行調(diào)試時如何解決跨域問題,下面小編給大家分享解決方法,感興趣的朋友一起看看吧2017-10-10
關(guān)于實現(xiàn)Vue3版抖音滑動插件踩坑指南
這篇文章主要給大家介紹了關(guān)于實現(xiàn)Vue3版抖音滑動插件踩坑指南,文中通過實例代碼介紹的非常詳細,對大家學(xué)習或者使用vue3具有一定的參考學(xué)習價值,需要的朋友可以參考下2022-02-02
Vue中transition單個節(jié)點過渡與transition-group列表過渡全過程
這篇文章主要介紹了Vue中transition單個節(jié)點過渡與transition-group列表過渡全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04

