How to use momentJs to make a countdown component
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)