獲取當(dāng)前時(shí)間,進(jìn)行轉(zhuǎn)換
getTime:function(){
var _this = this;
let yy = new Date().getFullYear();
let mm = new Date().getMonth()+1;
let dd = new Date().getDate();
let hh = new Date().getHours();
let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
_this.gettime = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
},
創(chuàng)建定時(shí)器
currentTime(){
setInterval(this.getTime,500)
},
在生命周期函數(shù)中觸發(fā)定時(shí)器
created() {
this.currentTime();
},
<p>{{gettime}}</p>
data() {
return {
gettime:'',//當(dāng)前時(shí)間
},