<template>
<div>
{{nowTime}}
</div>
</template>
<script>
export default {
name:"",
data(){
return {
currentTime:'',//当前时间
}
},
methods:{
NowTime(){
this.currentTime = this.CustomMethods.getCurrentTime()
}
},
mounted() {
this.timer = setInterval(()=> {
this.NowTime(new Date()) // 修改数据date
}, 500)
},
destroyed() {
if (this.timer) { // 注意在vue实例销毁前,清除我们的定时器
clearInterval(this.timer);
}
}
}
</script>
<style lang="scss" scope>
</style>
vue获取当前时间并且实时更新
最新推荐文章于 2023-12-06 09:54:52 发布