Vue js实时显示当前时间
当前实例在vue项目中export default {data(){return{nowTimes:{yy:0,dd:"00",hou:"00",min:"00",sec...
·
当前实例在vue项目中
export default {
data(){
return{
nowTimes:{
yy:0,
dd:"00",
hou:"00",
min:"00",
sec:"00"
},
setTime:null
}
},
mounted(){
this.setTime = setInterval( ()=>{
this.setNowTimes();
},1000)
},
methods:{
setNowTimes(){
let myDate = new Date();
this.nowTimes.yy = myDate.getMonth()+1;
this.nowTimes.dd = String(myDate.getDate()<10?'0'+ myDate.getDate(): myDate.getDate()) ;
this.nowTimes.hou = String(myDate.getHours()<10?"0"+myDate.getHours():myDate.getHours());
this.nowTimes.min = String(myDate.getMinutes()<10?'0'+myDate.getMinutes():myDate.getMinutes());
this.nowTimes.sec = String(myDate.getSeconds()<10?'0'+myDate.getSeconds():myDate.getSeconds());
}
},
beforeUpdate(){
clearInterval(this.setTime)
}
}
vue项目就直接用吧!
更多推荐
已为社区贡献8条内容
所有评论(0)