npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-plugin-exposure

v1.0.0

Published

vue插件 曝光组件 使用intersection-observer

Readme

vue-plugin-exposure

vue插件 曝光组件 使用intersection-observer

demo

Github Page Demo

cmd 调用方式:

安装

yarn add vue-plugin-exposure --save

通过 imort 导入

import Exposure from 'vue-plugin-exposure';

使用

初始化

调用 Face 构造函数,实例化组件对象:

const config = {
  name: 'exposure',
  // 其他曝光相关配置,可参考 IntersectionObserver
  // 已做默认配置如下
  // threshold: [0],
  // root: null,
  // rootMargin: '0px 0px -50px 0px'
};

// or
Vue.use(Exposure, config);

组件中使用

注意,通过指令 例如v-exposure="doExpose" 传到插件中的是一个函数,会在曝光时调用,所以不要再模板上传参。
vue中的数据可以直接在对应函数的this中拿到,如下例(TS的例子,使用插件的方法不会变)

xxx.vue

<template>
  <section class="online_row" v-exposure="doExpose">
    <span class="online_call_btn">立即抢答</span>
  </section>
</template>
<script lang="ts">
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator';

@Component({})
export default class LiveAnswer extends Vue {
  @Prop(Object)
  private cardData!: any;

  private COMP_NAME = 'LiveAnswer';

  mounted() {}

  destroyed() {}

  // methods
  private doExpose() {
    this.$emit('do-expose', { data: this.cardData, from: this.COMP_NAME });
  }
}
</script>

如果一定要在模板上传参,请封装一个高阶函数,如下:

<template>
  <section class="online_row" @click="doClick('raceAnswer', $event)" v-exposure="doExpose('test1')">
    <span class="online_call_btn">立即抢答</span>
  </section>
</template>
<script lang="ts">
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator';

@Component({})
export default class LiveAnswer extends Vue {
  @Prop(Object)
  private cardData!: any;

  private COMP_NAME = 'LiveAnswer';

  mounted() {}

  destroyed() {}

  // methods
  private doClick(type, event) {
    event.stopPropagation();
    this.$emit('do-click', { event, type, data: this.cardData, from: this.COMP_NAME });
  }

  private doExpose(domParams) {
    return () => {
      console.log(domParams, this);
      this.$emit('do-expose', { data: this.cardData, from: this.COMP_NAME });
    };
  }
}
</script>

name 插件名称

default:'exposure'
name: 'xxx', 插件名为 v-xxx

root 滑动根节点

default: null
root: null 默认指定滑动根节点为 document

threshold 触发阈值

defalut: [0]

数组长度可以为1 或 2 或 4. 和css选择器规则一样 分别代表四个方向的交叉值 比如 threshold: [0] 表示无论从 上下左右哪个方向进入容器可视区内部 都会触发

需注意 数组内容为 0~1 之间的小数,代表交叉比例。 比如监听的dom 高度40px, 设置 threshold: [0.5],则在漏出 20px 之后会触发事件。

rootMargin 边框边距

default: '0px 0px -50px 0px'
举例来说,比如我们就是想漏出44px(之所以设置这个值是因为APP上评论条刚好这么高而且盖在Webview上方)之后触发事件,但是节监听的dom高度不一致或不可预知,默认配置就是解决这个场景