代码如下:
var vm =new Vue({
el:'#app',
data:{
years:0,
months:0,
days:0,
hours:0,
seconds:0,
minutes:0,
},
mounted:function(){
var _this=this;
setInterval(function () {
_this.get();
}, 1000)
},
methods:{
get:function () {
var start = new Date();
var end = new Date(2019,3,28,17,2,0);
var elapse = Math.floor((end - start) / 1000);
this.seconds = elapse % 60 ;
this.minutes = Math.floor(elapse / 60) % 60;
this.hours = Math.floor(elapse / (60 * 60)) % 24;
this.days = Math.floor(elapse / (60 * 60 * 24)) % 30;
this.months = Math.floor(elapse / (60 * 60 * 24 * 30)) % 12;
this.years = Math.floor(elapse / (60 * 60 * 24 * 30 * 12));
},
}
})