vue.JS如何显示时间

  介绍

这篇文章主要介绍vue.JS如何显示时间,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

vue.JS显示时间的方法:首先在数据中定义一个变量,存储时间,代码为【数据(){返回{nowTime: & # 39; & # 39;}}】,然后给定一个div,代码为【& lt; div> {{nowTime}} & lt;/div>】。

<强> vue.JS显示时间的方法:

<强> 1。在数据中定义一个变量,存储时间

数据(){   ,,return  {   ,,,,nowTime: & # 39; & # 39;   ,,}   ,,},

<强> 2。给定一个div

& lt; div> {{nowTime}} & lt;/div>

<强> 3。js部分

,//显示当前时间(年月日时分秒)   ,,,timeFormate(时间戳),{   ,,,,,let  year =, new 日期(时间戳).getFullYear ();   ,,,,,let  month =new 日期(时间戳).getMonth (), +, 1, & lt;, 10 ?,“0”, +, (new 日期(时间戳).getMonth (), +, 1):, new 日期(时间戳).getMonth (), +, 1;   ,,,,,let  date =new 日期(时间戳).getDate (), & lt;, 10 ?,“0”, +, new 日期(时间戳).getDate ():, new 日期(时间戳).getDate ();   ,,,,,let  hh =new 日期(时间戳).getHours (), & lt;, 10 ?,“0”, +, new 日期(时间戳).getHours ():, new 日期(时间戳).getHours ();   ,,,,,let  mm =new 日期(时间戳).getMinutes (), & lt;, 10 ?,“0”, +, new 日期(时间戳).getMinutes ():, new 日期(时间戳).getMinutes ();   ,,,,,let  ss =new 日期(时间戳).getSeconds (), & lt;, 10 ?,“0”, +, new 日期(时间戳).getSeconds ():, new 日期(时间戳).getSeconds ();   ,,,,,this.nowTime =, year  +,“年”,+,month  +,“月“,+,date  +“日”+“,“+ hh +“:“+ mm + & # 39;: & # 39; + ss ;   ,,,},   ,,,nowTimes () {   ,,,,,this.timeFormate (new 日期());   ,,,,,setInterval (this.nowTimes, 1000);   ,,,,,this.clear ()   ,,,},   ,,,明确(){   ,,,,,clearInterval (this.nowTimes)   ,,,,,this.nowTimes =,空;   ,,,}

<强> 4。复制粘贴即可用,主要是使用定时器,每秒调用,最后清除定时器,清除函数

以上是“vue.JS如何显示时间”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

vue.JS如何显示时间