话不多说直接上代码了
created() {
this.$nextTick(() => {
setInterval(() => {
var dd = new Date()
var year = dd.getFullYear()
var month = dd.getMonth() + 1
var day = dd.getDate()
var hour = dd.getDate()
var mins = dd.getMinutes()
var second = dd.getSeconds()
this.$refs.date.innerHTML = `${year}-${month}-${day} ${hour}:${mins}:${second}`
})
})
}
<span ref="date"></span>
注意要使用箭头函数,不然this指向出现问题