Socket
Socket
Sign inDemoInstall

vuejs-countdown-timer

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vuejs-countdown-timer

Vue 2 countdown and timer component


Version published
Weekly downloads
944
decreased by-37.69%
Maintainers
1
Install size
24.6 kB
Created
Weekly downloads
 

Changelog

Source

2.1.3 (Oct 012, 2020)

Bug fixes 🐛

  • Fixed the time convert browser compatibility issue #12

Readme

Source

TriDiamond logo

Vue-countdown-timer Component

Vue 2 countdown and timer component
—— Made with ❤️ by TriDiamond

Build Status Github starts License Npm downloads Npm version

Demo 📙 中文文档 📙Changelog

Installation

npm i vuejs-countdown-timer -S

Usage

Support

Supported PackageVersion
Vue2.5+

Install component and Usage

Import component

// global register at main.js
import VueCountdownTimer from 'vuejs-countdown-timer';
Vue.use(VueCountdownTimer);

Vue default template

<template>
    <vue-countdown-timer
      @start_callback="startCallBack('event started')"
      @end_callback="endCallBack('event ended')"
      :start-time="'2018-10-10 00:00:00'"
      :end-time="1481450115"
      :interval="1000"
      :start-label="'Until start:'"
      :end-label="'Until end:'"
      label-position="begin"
      :end-text="'Event ended!'"
      :day-txt="'days'"
      :hour-txt="'hours'"
      :minutes-txt="'minutes'"
      :seconds-txt="'seconds'">
    </vue-countdown-timer>
</template>

<script >
export default {
  name: 'Timer',
  methods: {
    startCallBack: function(x) {
      console.log(x);
    },
    endCallBack: function(x) {
      console.log(x);
    },
  },
};
</script>

Vue Customized template

<template>
    <vue-countdown-timer
      @start_callback="startCallBack('event started')"
      @end_callback="endCallBack('event ended')"
      :start-time="'2018-10-10 00:00:00'"
      :end-time="1481450115"
      :interval="1000"
      :start-label="'Until start:'"
      :end-label="'Until end:'"
      label-position="begin"
      :end-text="'Event ended!'"
      :day-txt="'days'"
      :hour-txt="'hours'"
      :minutes-txt="'minutes'"
      :seconds-txt="'seconds'">
      <template slot="start-label" slot-scope="scope">
        <span style="color: red" v-if="scope.props.startLabel !== '' && scope.props.tips && scope.props.labelPosition === 'begin'">{{scope.props.startLabel}}:</span>
        <span style="color: blue" v-if="scope.props.endLabel !== '' && !scope.props.tips && scope.props.labelPosition === 'begin'">{{scope.props.endLabel}}:</span>
      </template>

      <template slot="countdown" slot-scope="scope">
        <span>{{scope.props.days}}</span><i>{{scope.props.dayTxt}}</i>
        <span>{{scope.props.hours}}</span><i>{{scope.props.hourTxt}}</i>
        <span>{{scope.props.minutes}}</span><i>{{scope.props.minutesTxt}}</i>
        <span>{{scope.props.seconds}}</span><i>{{scope.props.secondsTxt}}</i>
      </template>

      <template slot="end-label" slot-scope="scope">
        <span style="color: red" v-if="scope.props.startLabel !== '' && scope.props.tips && scope.props.labelPosition === 'end'">{{scope.props.startLabel}}:</span>
        <span style="color: blue" v-if="scope.props.endLabel !== '' && !scope.props.tips && scope.props.labelPosition === 'end'">{{scope.props.endLabel}}:</span>
      </template>

      <template slot="end-text" slot-scope="scope">
        <span style="color: green">{{ scope.props.endText}}</span>
      </template>
    </vue-countdown-timer>
</template>

<script >
export default {
  name: 'Timer',
  methods: {
    startCallBack: function(x) {
      console.log(x);
    },
    endCallBack: function(x) {
      console.log(x);
    },
  },
};
</script>

Slots

Slot nameDescription
start-labelTimer start label
countdownTimer countdown label
end-labelTimer end label
end-textTimer ended text

start-label Scoped Slot

Slot scope nameDescription
startLabelEvent begin label text
endLabelEvent end label text
tipsTips true means countdown till start, false means countdown till end
labelPositionevent label position, 'begin' or 'end'

countdown Scoped Slot

Slot scope nameDescription
daysNumber of days till event
dayTxtDay label
hoursNumber of hours till event
hourTxtHours label
minutesNumber of minutes till event
minuteTxtMinutes label
secondsNumber of seconds till event
secondTxtSeconds label
showDaydisplay status of day countdown number and text
showHourdisplay status of hour countdown number and text
showMinutedisplay status of minute countdown number and text

end-label Scoped Slot

Slot scope nameDescription
startLabelEvent begin label text
endLabelEvent end label text
tipsTips true means countdown till start, false means countdown till end
labelPositionevent label position, 'begin' or 'end'

end-text Scoped Slot

Slot scope nameDescription
endTextTimer ended text

Props

start-time

  • type: Number|String
  • required : true

end-time

  • type: Number|String
  • required : true

interval

  • type: Number
  • required : false
  • default : 1000

start-label

  • type: String
  • required : false
  • default : ''

end-label

  • type: String
  • required : false
  • default : ''

label-position - begin (before countdown) / end (after countdown)

  • type: String
  • required : false
  • default : 'begin'

end-text

  • type: String
  • required : false
  • default : 'Event ended!'

day-txt - if pass null, this unit will be hidden

  • type: String
  • required : false
  • default : ':'

hour-txt - if pass null, this unit will be hidden

  • type: String
  • required : false
  • default : ':'

seconds-txt - if pass null, this unit will be hidden

  • type: String
  • required : false
  • default : ':'

seconds-fixed

  • type: String
  • required : false
  • default : ':'

show-zero - display status of 00

  • type: Boolean
  • required : false
  • default : true

Events

start_callback - Event started callback

  • type: Function
  • required : false

end_callback - Event ended callback

  • type: Function
  • required : false

If the end-time prop is dynamically generated or 'computed', the initial value will be NaN. This will trigger the end_callback function, which might not be desirable. This can be solved by declaring it this way:

<template>
  <vue-countdown-timer
    ...
    :end-time="end_at?end_at:endAt"
    ...
    ></vue-countdown-timer>
</template>
<script>
  data() {
      return {
          endAt:  (new Date).getTime()+5000
      }
  }
</script>

Where end_at is the computed value, and endAt is a default value.

Liscense

MIT License

Keywords

FAQs

Last updated on 12 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc