Tagged: @xkeshi/vue-countdown

Vue Js Countdown Timer Vue Component 0

Vue Js Countdown Timer Vue Component

Today, We want to share with you Vue Js Countdown Timer Vue Component.In this post we will show you Countdown Timer using Vue.js, hear for Countdown component for Vue.js we will give you demo and example for implement.In this post, we will learn about Countdown Timer Until Date Vue JS with an example.

Vue Js Countdown Timer Vue Component

There are the Following The simple About Vue Js Countdown Timer Vue Component Full Information With Example and source code.

As I will cover this Post with live Working example to develop @chenfengyuan/vue-countdown, so the npm vue countdown for this example is following below.

vuejs component

<countdown date="August 15, 2019"></countdown>

./components/Countdown.vue

<template>
    <div class="main-Cart">
        <p class="display-number">{{ days }}</p>
        <p class="text">Days</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ hours }}</p>
        <p class="text">Hours</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ minutes }}</p>
        <p class="text">Minutes</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ seconds }}</p>
        <p class="text">Seconds</p>
    </div>
</template>

style CSS Part

@import url(https://fonts.googleapis.com/css?family=Roboto+Condensed:400|Roboto:100);

.main-Cart {
    display: flex;
    flex-direction: column;
    margin: 20px;
}

.text {
    color: #1abc9c;
    font-size: 40px;
    font-family: 'Roboto Condensed', serif;
    font-weight: 40;
    margin-top:10px;
    margin-bottom: 10px;
    text-align: center;
}

.display-number {
    color: #ecf0f1;
    font-size: 150px;
    font-weight: 100;
    font-family: 'Roboto', serif;
    margin: 10px;
    text-align: center;
}

Vuejs Script Code

<script>
export default {

    props : {
        date : {
            type: Number,
            coerce: str => Math.trunc(Date.parse(str) / 1000)
        }
    },

    data() {
        return {
            now: Math.trunc((new Date()).getTime() / 1000)
        }
    }

    /* Computed properties will be here */
}
</script>

window.setInterval

ready() {
    window.setInterval(() => {
        this.now = Math.trunc((new Date()).getTime() / 1000);
    },1000);
}

computed properties

computed: {
    seconds() {
        return (this.date - this.now) % 60;
    },

    minutes() {
        return Math.trunc((this.date - this.now) / 60) % 60;
    },

    hours() {
        return Math.trunc((this.date - this.now) / 60 / 60) % 24;
    },

    days() {
        return Math.trunc((this.date - this.now) / 60 / 60 / 24);
    }
}

main.js

Vue.filter('live_display-numbers_preview', function (value) {
    if(value.toString().length <= 1)
    {
        return "0"+value.toString();
    }
    return value.toString();
});

update the template

<template>
    <div class="main-Cart">
        <p class="display-number">{{ days | live_display-numbers_preview }}</p>
        <p class="text">Days</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ hours | live_display-numbers_preview }}</p>
        <p class="text">Hours</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ minutes | live_display-numbers_preview }}</p>
        <p class="text">Minutes</p>
    </div>
    <div class="main-Cart">
        <p class="display-number">{{ seconds | live_digits_preview }}</p>
        <p class="text">Seconds</p>
    </div>
</template>

App.vue

<template>
  <div id="app">
      <Countdown date="August 15, 2019"></Countdown>
  </div>
</template>

<script>
import Countdown from './components/Countdown.vue';

export default {
    components: { Countdown },
}
</script>

<style>
#app {
    align-items: center;
    bottom: 0;
    background-color: #34495e;
    display: flex;
    justify-content: center;
    left: 0;
    position: absolute;
    right: 0;
    top:0;
}
</style>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Vue Js Countdown Timer Vue Component.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.