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 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-countdown-demi

v1.0.0

Published

template component for vue-demi, can dev and build

Downloads

8

Readme

vue-countdown-demi

一款适用于Vue2、Vue2.7、Vue3的带有可选控件的倒计时组件

npm包文件

dist
├── v2
|    ├──── index.cjs.js
|    ├──── index.es.js
|    ├──── index.umd.js
├── v2.7
|    ├──── index.cjs.js
|    ├──── index.es.js
|    ├──── index.umd.js
├── v3
     ├──── index.cjs.js
     ├──── index.es.js
     ├──── index.umd.js

安装

使用npm:

npm install vue-countdown-demi

使用pnpm:

pnpm add vue-countdown-demi

使用Yarn:

yarn add vue-countdown-demi

如何使用

#main.ts

import Vue from 'vue'
import TemplateComponent from 'vue-countdown-demi'
import App from './App.vue'

Vue.config.productionTip = false
Vue.use(TemplateComponent)

new Vue({ render: h => h(App) }).$mount('#app')

基础用法

<template>
  <vue-countdown :time="2 * 24 * 60 * 60 * 1000" v-slot="{ days, hours, minutes, seconds }">
    Time Remaining:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds.
  </vue-countdown>
</template>

自定义循环时间

<template>
  <vue-countdown :time="time" :interval="100" v-slot="{ days, hours, minutes, seconds, milliseconds }">
    New Year Countdown:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }}.{{ Math.floor(milliseconds / 100) }} seconds.
  </vue-countdown>
</template>

<script>
export default {
  data() {
    const now = new Date();
    const newYear = new Date(now.getFullYear() + 1, 0, 1);

    return {
      time: newYear - now,
    };
  },
};
</script>

格式化slot props

<template>
  <vue-countdown :time="2 * 24 * 60 * 60 * 1000" :transform="transformSlotProps" v-slot="{ days, hours, minutes, seconds }">
    Time Remaining:{{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds.
  </vue-countdown>
</template>

<script>
export default {
  methods: {
    transformSlotProps(props) {
      const formattedProps = {};

      Object.entries(props).forEach(([key, value]) => {
        formattedProps[key] = value < 10 ? `0${value}` : String(value);
      });

      return formattedProps;
    },
  },
};
</script>

按需倒计时

<template>
  <button type="button" class="btn btn-primary" :disabled="counting" @click="startCountdown">
    <vue-countdown v-if="counting" :time="60000" @end="onCountdownEnd" v-slot="{ totalSeconds }">Fetch again {{ totalSeconds }} seconds later</vue-countdown>
    <span v-else>Fetch Verification Code</span>
  </button>
</template>

<script>
export default {
  data() {
    return {
      counting: false,
    };
  },
  methods: {
    startCountdown: function () {
      this.counting = true;
    },
    onCountdownEnd: function () {
      this.counting = false;
    },
  },
};
</script>

Props

| 参数 | 类型 | 默认值 | 描述 | | ----------- | ---------- | -------------------------- | ------------------------------------------------------------ | | auto-start | boolean | true | 组件初始化时是否自动开启倒计时 | | emit-events | boolean | true | 组件是否emit倒计时事件 | | interval | number | 1000 | 倒计时间隔时间(单位:ms),该值不应该小于0 | | now | Function | () => Date.now() | 当前时间(单位:ms) | | tag | string | "span" | 组件根元素标签 | | time | number | 0 | 倒计时的时间(单位:ms) | | transform | Function | (slotProps) => slotProps | 在渲染前输出slotProps,该对象包含以下属性: days, hours, minutes, seconds, milliseconds, totalDays, totalHours, totalMinutes, totalSeconds, 以及 totalMilliseconds. |

Methods

| 事件名称 | 回调参数 | 说明 | | ------- | ---------- | ------------------------------------------------------------ | | start | () | 开始倒计时。当props auto-start设置为 true时自动执行 | | abort | () | 立即终止倒计时 | | end | () | 手动结束倒计时 | | restart | () | 重新开始倒计时 |

Events

| 事件名称 | 回调参数 | 说明 | | -------- | ---------- | ------------------------------------------------------------ | | start | () | 倒计时开始时触发 | | progress | (data) | 倒计时进行时持续触发。data对象包含以下属性: days, hours, minutes, seconds, milliseconds, totalDays, totalHours, totalMinutes, totalSeconds, 以及 totalMilliseconds. | | abort | () | 倒计时终止时触发 | | end | () | 倒计时结束时触发 |

所有冒泡事件都是可选的

Note: 你可以设置 emit-events: false 来提高组件性能。

License

Made with 💙

Published under MIT License.