Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use momentJs to make a countdown component

Shulou Source: shulou.com Published: 2022-06-02 06:14:05 10月04日 Update

Today, I will talk to you about how to use momentJs to do a countdown component, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Vue and moment did a countdown.

Display style:

{{item}}: {{item}}: {{item}} import moment from 'moment'export default {props: {endTime: {}, / / the last time received is 2021-12-17 16:29:20}, data () {/ / the data is stored here. MRV, sRV, timer:null} }, watch: {endTime: {handler (e) {if (e) {let self = this clearInterval (this.timer) this.timer = setInterval (function () {self.init ()}, 1000)}, deep: true, immediate: true}} Mounted () {let self = this self.init () clearInterval (this.timer) this.timer = setInterval (function () {self.init ()}, 1000)}, / / method collection methods: {init () {let time = moment (this.endTime) .diff (moment ()) if (time)

Tags: Countdown days content components hours data methods time more styles knowledge articles industry information information channels channels enter one remaining support related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Huawei vpn Apple