效果:
html:
<div class="time">
<ul>
<li>
{{ dateObj.date }}
</li>
<li>
{{ dateObj.week }}
</li>
</ul>
</div>
js:
export default {
data() {
return {
dateObj: {
year:"",
month:"",
date: "",
week: "",
// timer: null,
},
};
},
methods: {
getDateTime() {
const ddd = this;
function getDateFun() {
let d = new Date();
let year = d.getFullYear();
let month = d.getMonth();
let date = d.getDate();
let day = d.getDay();
let weekday = [
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
];
ddd.dateObj.date = year + '-' + month + '-' + date;
//ddd.dateObj.date = `${year}-${month}-${date}`;
ddd.dateObj.week = weekday[day];
}
getDateFun();
},
},
mounted() {
this.getDateTime();
},
};