<script> new Vue({ el: '#app', data() { return { clock: '', } }, mounted() { this.$nextTick(() => { setInterval(this.CurentTime, 1000); }) }, methods: { CurentTime() { var getTime = new Date(); var year = getTime.getFullYear(); //年 var month = getTime.getMonth() + 1; //月 var day = getTime.getDate(); //日 var hh = getTime.getHours(); //时 var mm = getTime.getMinutes(); //分 var ss = getTime.getSeconds(); //秒 var clock = year + "-"; if (month < 10) clock += "0"; clock += month + "-"; if (day < 10) clock += "0"; clock += day + " "; if (hh < 10) clock += "0"; clock += hh + ":"; if (mm < 10) clock += '0'; clock += mm + ":"; if (ss < 10) clock += '0'; clock += ss; this.clock = clock } }, }) </script>