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-canteen

v1.0.21

Published

一个简单而高效实用的工具库

Readme

vue-canteen

一个简单而高效实用的工具库

directive 指令

vDebounce 防抖

import { vDebounce } from "vue-canteen";
<!-- 默认click事件 - 默认间隔时间1000ms - 首次不触发-->
<div v-debounce="handle"></div>
<!-- 默认click事件 - 间隔时间1500ms - 首次不触发-->
<div v-debounce.1500="handle"></div>
<!-- 鼠标移动事件 - 间隔500ms - 首次立即执行 -->
<div v-debounce:mousemove.500.immediate="handle"></div>

vThrottling 节流

import { vThrottling } from "vue-canteen";
<!-- 默认click事件 - 默认间隔时间1000ms-->
<div v-throttling="handle"></div>
<!-- 鼠标移动事件 - 间隔500ms -->
<div v-throttling:mousemove.500="handle"></div>

vFocus 聚焦

基础用法

<template>
  <input type="text" v-focus />
</template>
<script setup>
import { vFocus } from "vue-canteen";
</script>

异步方法

<template>
  <input type="text" v-focus="handle" />
</template>
<script setup>
import { vFocus } from "vue-canteen";
const handle = async () => {
  return (
    new Promise() <
    boolean >
    ((resolve) => {
      setTimeout(() => {
        resolve(true);
      }, 5000);
    })
  );
};
handle();
</script>

vLoading 加载

基础用法

<template>
  <div v-loading="loading">容器</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { vLoading } from "vue-canteen";

const loading = ref<boolean>(false);
</script>

自定义组件

<template>
  <div v-loading:[CustomLoading]="loading">容器</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { vLoading } from "vue-canteen";
import CustomLoading from "./customLoading.vue";

const loading = ref<boolean>(false);
</script>

vCopy 复制

基础用法

<template>
  <button v-copy:[str]>copy</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { vCopy } from "vue-canteen";

const str = ref<string>("树叶的一生只是为了归根吗?");
</script>

事件回调

<template>
  <button v-copy:[str]="handle">copy</button>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { vCopy } from "vue-canteen";

const str = ref<string>("疾风亦有归途");

const handle = (error) => {
  if (!error) {
    alert("复制成功");
    return;
  }
  alert("复制失败");
};
</script>

<style scoped></style>

hooks

useNumberAnimation 数字增长

<template>
  <div>
    <button @click="start">开始</button>
    <button @click="paused">暂停</button>
    <button @click="stop">结束</button>

    <div>
      倒计时: <b>{{ countDown }}</b>
    </div>

    <p>
      当前状态:<b>{{ stateInfo.get(state) }}</b>
    </p>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import {
  ITimeInfo,
  useNumberAnimation,
  UseNumberAnimationStatus,
} from "vue-canteen";

const countDown = ref<number>(100);

const state = ref<UseNumberAnimationStatus>(UseNumberAnimationStatus.Wait);

const stateInfo = new Map();
stateInfo.set(UseNumberAnimationStatus.Wait, "等待开始");
stateInfo.set(UseNumberAnimationStatus.Progress, "正在执行");
stateInfo.set(UseNumberAnimationStatus.Paused, "已暂停");
stateInfo.set(UseNumberAnimationStatus.End, "执行结束");

const animate = useNumberAnimation({
  from: 1, // 起始值
  to: 100, // 目标值
  duration: 3000, // 执行时间
  // 开始回调
  onStart(status: UseNumberAnimationStatus) {
    state.value = status;
  },
  // 执行进度回调
  onProgress(
    value: number,
    timeInfo: ITimeInfo,
    status: UseNumberAnimationStatus
  ) {
    state.value = status;
    countDown.value = Math.floor(value);
  },
  // 暂停回调
  onPaused(timeInfo: ITimeInfo, status: UseNumberAnimationStatus) {
    state.value = status;
  },
  // 结束回调
  onStop(value, timeInfo, status) {
    state.value = status;
  },
});

const start = () => animate.start();
const paused = () => animate.paused();
const stop = () => animate.stop();
</script>

useWebSocket 全双工通信

<template>
  <div>
    <button @click="connect">连接</button>
    <button @click="send">发送</button>
    <button @click="close">关闭</button>
  </div>
</template>

<script setup lang="ts">
import { useWebSocket } from "vue-canteen";

const socket = useWebSocket(
  {
    url: "ws://192.168.2.207:8080",
    immediate: false, // 是否立即连接
    // 消息回调
    onMessage(data, instance, status, ev) {
      console.log("🚀 Message", data);
    },
    // 连接成功回调
    onConnect(instance, status, ev) {
      console.log("🏀 Connect");
    },
    // 连接失败回调
    onDisConnect(instance, status, ev) {
      console.log("🔓 DisConnect");
    },
    // 错误回调
    onError(instance, status, ev) {
      console.log("❌ Error");
    },
  },
  // 断线重连
  {
    interval: 3000, // 间隔时间
    count: 5, // 重连次数
  },
  // 心跳包
  {
    interval: 1000, // 间隔时间
    heartbeat: "ping", // 心跳包数据
  }
);

const connect = () => {
  socket.connect();
};
const send = () => {
  socket.send("1");
};
const close = () => {
  socket.close();
};
</script>

useLoading 加载

基本使用

<template>
  <button @click="handle">
    {{ flag ? "hide" : "show" }}
  </button>
  <div id="loading-container">container</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useLoading } from "vue-canteen";

const flag = ref<boolean>(false);

const loading = useLoading({
  // 需要添加loading的容器
  target: "#loading-container",
});

const handle = () => {
  flag.value = !flag.value;
  flag.value ? loading.show() : loading.hide();
};
</script>

自定义 Loading

<template>
  <button @click="handle">
    {{ flag ? "hide" : "show" }}
  </button>
  <div id="loading-container__custom">container</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useLoading } from "vue-canteen";
// 隐去自定义组件
import CustomLoading from "./customLoading.vue";
import { h } from "vue";

const flag = ref<boolean>(false);

const loading = useLoading({
  target: "#loading-container__custom",
  component: h(CustomLoading),
  // 添加容器类名,可自行修改外层样式
  wrapClass: "customClass",
});

const handle = () => {
  flag.value = !flag.value;
  flag.value ? loading.show() : loading.hide();
};
</script>

延时关闭

调用 hide 方法后,延时关闭

<template>
  <button @click="handle">
    {{ flag ? "hide" : "show" }}
  </button>
  <div id="loading-container__delay">container</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useLoading } from "vue-canteen";

const flag = ref<boolean>(false);

const loading = useLoading({
  target: "#loading-container__delay",
  // 延时关闭时间
  delay: 2000,
  wrapClass: "customClass",
});

const handle = () => {
  flag.value = !flag.value;
  flag.value ? loading.show() : loading.hide();
};
</script>