vue加载js延迟_小型Vue.js指令,用于使用IntersectionObserver API延迟加载图像

vue加载js延迟

vue-tiny-lazyload-img (vue-tiny-lazyload-img)

A small size Vue.js directive for lazy loading images using IntersectionObserver API.

小型Vue.js指令,用于使用IntersectionObserver API延迟加载图像。

用法 (Usage)

下载 (Download)

npm install vue-tiny-lazyload-img
// OR
yarn add intersection-observer

安装插件 (Install Plugin)

import VueTinyLazyloadImg from 'vue-tiny-lazyload-img'
Vue.use(VueTinyLazyloadImg);

HTML片段 (HTML Snippet)

<img v-lazyload
  src="./assets/logo.png"
  data-src="./assets/logo-success.png"
  data-err="./assets/logo-error.png">

请使用polyfill (Please Use polyfill)

This plugin using IntersectionObserver, so please use polyfill if you need support old browser

该插件使用IntersectionObserver ,因此如果需要支持旧版浏览器,请使用polyfill

$ yarn add intersection-observer

// then add polyfill for IntersectionObserver in your main app
require('intersection-observer')
  • The easiest way to load the IntersectionObserver polyfill and have it work in the widest range of browsers is via polyfill.io, which will automatically include dependencies where necessary:

    加载IntersectionObserver polyfill并使它在最广泛的浏览器中运行的最简单方法是通过polyfill.io ,它会在必要时自动包含依赖项:

<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>

构建设置 (Build Setup)

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production demo with minification
npm run build:demo

# build for plugin distribution file
npm run build:lib

翻译自: https://vuejsexamples.com/a-small-size-vue-js-directive-for-lazy-loading-images-using-intersectionobserver-api/

vue加载js延迟

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值