1.1.4 • Published 2 years ago

vue-countdown-plus v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

vue-countdown-plus

A simple countdown component for Vue2.x.

Live Demo

Installation

npm install vue-countdown-plus --save

Usage

Basic

<countdown-plus :time="30 * 60 * 60 * 1000" />

Custom Format

<countdown-plus
  :time="30 * 60 * 60 * 1000"
  format="DD ~Day, HH:mm:ss"
/>

Custom Style

<countdown-plus
  :time="30 * 60 * 60 * 1000"
  format="HH:mm:ss"
>
  <template v-slot="{ resolved }">
    <span class="countdown-item">{{ resolved.HH }}</span> :
    <span class="countdown-item">{{ resolved.mm }}</span> :
    <span class="countdown-item">{{ resolved.ss }}</span>
  </template>
</countdown-plus>

Masual Control

<div>
  <countdown-plus
    ref="countdown"
    :time="30 * 60 * 60 * 1000"
    :auto-start="false"
  />
  <div class="control-buttons">
    <button @click="start">Start</button>
    <button @click="pause">Pause</button>
    <button @click="reset">Reset</button>
  </div>
</div>
export default {
  methods: {
    start() {
      this.$refs.countdown.start()
    },
    pause() {
      this.$refs.countdown.stop()
    },
    reset() {
      this.$refs.countdown.reset()
    }
  }
}

Second Count Down

<countdown-plus :time="60 * 1000" format="ss" />

Events

<countdown-plus
  :time="5 * 1000"
  format="ss"
  @change="handleChange"
  @finish="handleFinish"
/>
export default {
  methods: {
    handleChange ({ currentTime, resolved, formatted }) {
      console.log(currentTime, resolved, formatted)
    },
    handleFinish () {
      console.log('finished')
    }
  }
}

API

Props

PropDescriptionTypeDefault
timeTotal timenumber0
formatTime formatstringHH:mm:ss
auto-startWhether to auto start count downbooleantrue

Available formats

FormatDescription
DDay
DDDay, leading zero
HHour
HHHour, leading zero
mMinute
mmMinute, leading zero
sSecond
ssSecond, leading zero
SMillisecond, 1-digit
SSMillisecond, 2-digit

If you don't want to convert a unit charactor you can prefixing the character ~ before the unit character.

For example, format prop DD Day HH:mm:ss will be converted to 01 1ay HH:mm:ss, the word Day is incorrectly converted to 1ay. Using DD ~Day HH:mm:ss can solve this problem.

Events

EventDescriptionArguments
changeEmitted when count down changed{ currentTime, resolved, formatted }
finishEmitted when count down finished-

Slots

NameDescriptionSlotProps
defaultCustom Contentcountdown, resolved, formatted

SlotProps

NameTypeDescription
countdownnumberRemaining countdown
resolvedobjectRemaining countdown after resolving
formattedstringRemaining countdown after formatting

resolved is an object contains resolved countdown according to the format prop.

For example, resolved may be { mm: 10, ss: 10, SS: 10 } when format is mm:ss:SS. So you can custom display according resolved.

If an time unit is not in prop format, it will not be in resolved.

Methods

NameDescriptionAttributeReturn Value
startStart count down--
stopStop count down--
resetReset count down--

Attributes

NameTypeDescription
currentTimenumberRemaining countdown
resolvedobjectRemaining countdown after resolving
formattedstringRemaining countdown after formatting
inCountdownbooleanWhether in countdown

License

vue-countdown-plus is licensed under The MIT License.

1.1.4

2 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago