国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue-lazyload圖片延遲加載插件的實例講解

2019-11-19 14:22:43
字體:
來源:轉載
供稿:網友

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 // 這個是加載圖片數量})

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圖片延遲加載插件的實例講解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 华容县| 雷州市| 大丰市| 乌审旗| 内江市| 卓资县| 闻喜县| 同心县| 酒泉市| 温州市| 汶川县| 社旗县| 淮阳县| 灵山县| 太原市| 吉林省| 南和县| 昔阳县| 山东省| 东乡| 荔波县| 安达市| 新巴尔虎左旗| 民丰县| 宁波市| 龙井市| 和静县| 乳山市| 通河县| 淳化县| 尖扎县| 新津县| 宿迁市| 龙川县| 汉中市| 靖安县| 桓仁| 金坛市| 曲靖市| 双辽市| 绵阳市|