vue 动态添加元素组件_将交集观察者添加到Vue组件或HTML元素

vue 动态添加元素组件

Vue相交 (Vue Intersect)

A Vue component to add intersection-observer to a Vue component or HTML element.

Vue组件,用于将交叉观察器添加到Vue组件或HTML元素。

The IntersectionObserver is an amazing API which allows you to observe one or more HTMLElement for when it has entered or left the viewport.

IntersectionObserver是一个了不起的API,可让您观察一个或多个HTMLElement何时进入或离开视口。

This API has many use cases like, infinite-scroll, lazy-loading or animations when an element enters the viewport.

当一个元素进入视口时,此API有许多用例,例如无限滚动,延迟加载或动画。

安装 (Installation)

Simply install using your favorite package manager 🔥

只需使用您喜欢的软件包管理器进行安装install

NPM (NPM)
npm install vue-intersect --save
(Yarn)
yarn add vue-intersect

用法 (Usage)

The package acts as an abstract component, much like what you may know from keep-alive or transition.

该软件包充当抽象组件,就像您从keep-alivetransition可能了解的那样。

This means that it's basically a "decorator". A component which does not output any markup to the DOM, but adds the functionality under the hood 😱.

这意味着它基本上是一个“装饰器”。 一个组件,不向DOM输出任何标记,但在幕后adds添加了功能。

.vue (.vue)
<template>
  <intersect @enter="msg = 'Intersected'" @leave="msg = 'Not intersected'">
    <div>{{ msg }}</div>
  </intersect>
</template>

<script>
  import Intersect from 'vue-intersect'

  export default {
    components: { Intersect },
    data () {
      return {
        msg: 'I will change'
      }
    }
  }
</script>

现场演示 (Live Demo)

https://heavyy.github.io/vue-intersect/

https://heavyy.github.io/vue-intersect/

翻译自: https://vuejsexamples.com/add-intersection-observer-to-a-vue-component-or-html-element/

vue 动态添加元素组件

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值