Coder Social home page Coder Social logo

vue-countdown's Introduction

vue-countdown

Countdown component for Vue.js.

Table of contents

Main

dist/
├── vue-countdown.js        (UMD)
├── vue-countdown.min.js    (UMD, compressed)
├── vue-countdown.common.js (CommonJS, default)
└── vue-countdown.esm.js    (ES Module)

Getting started

Install

npm install @xkeshi/vue-countdown

Usage

  • Browser: window.VueCountdown
  • CommonJS: var VueCountdown = require('@xkeshi/vue-countdown')
  • ES2015: import VueCountdown from '@xkeshi/vue-countdown'
Vue.component('countdown', VueCountdown);
<countdown :time="2 * 24 * 60 * 60 * 1000">
  <template scope="props">Time Remaining:{{ props.days }} days, {{ props.hours }} hours, {{ props.minutes }} minutes, {{ props.seconds }} seconds.</template>
</countdown>
<!-- <span>Time Remaining:01 days, 23 hours, 59 minutes, 59 seconds.</span> -->

⬆ back to top

Props

auto-start

  • Type: Boolean
  • Default: true

Start to countdown automatically when initialized.

emit-events

  • Type: Boolean
  • Default: true

Indicate if emit the countdown events or not.

interval

  • Type: Number
  • Default: 1000

Update interval time (in milliseconds) of the countdown.

leading-zero

  • Type: Boolean
  • Default: true

Add a leading zero to the output days, hours, minutes and seconds if they are less than 10.

now

  • Type: Function
  • Default: () => Date.now()

Generate the current time (in milliseconds) of a specific time zone.

time

  • Type: Number
  • Default: 0

Total number of time (in milliseconds) for the countdown.

Note: The given value should not less than 0.

tag

  • Type: String
  • Default: 'span'

The tag of the component root element in the countdown.

Methods

start

Start to countdown.

<countdown v-bind:auto-start="false" ref="countdown"></countdown>
export default {
  mounted() {
    this.$refs.countdown.start();
  },
};

stop

Stop the countdown.

Events

Require to set the emit-events property to true, or if you don't need these events, you can set the prop to false for better performance.

countdownstart

This event fires when countdown started.

countdownprogress

This event fires when countdown in progress.

<countdown v-on:countdownprogress="onCountdownProgress"></countdown>
export default {
  methods: {
    onCountdownProgress(data) {
      console.log(data.days);
      console.log(data.hours);
      console.log(data.minutes);
      console.log(data.seconds);
    },
  },
};

countdownend

This event fires when countdown stopped.

⬆ back to top

Browser support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Opera (latest)
  • Edge (latest)
  • Internet Explorer 9+

Versioning

Maintained under the Semantic Versioning guidelines.

License

MIT © Xkeshi

⬆ back to top

vue-countdown's People

Contributors

fengyuanchen avatar joshuabehrens avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.