<template> <div class="container"> <div>当前系统时间:{{ dateTime }}</div> </div> </template> <script> export default { data() { return { dateTime: "", }; }, created() { this.Date(); }, methods: { //获取当前年月日 Date() { const nowDate = new Date(); const date = { year: nowDate.getFullYear(), month: nowDate.getMonth() + 1, date: nowDate.getDate(), }; const newmonth = date.month > 10 ? date.month : "0" + date.month; const day = date.date > 10 ? date.date : "0" + date.date; this.dateTime = date.year + "-" + newmonth + "-" + day; }, }, }; </script>