先上图,看看效果
项目git地址
思路:
实现获取当前时间,新建一个data
let now = new Date();
然后需要判断显示的是否为当月时间
if (cur) {
date = new Date(cur);
} else {
let now = new Date();
date = new Date(
/指定时间/
);
}
使用vue的v-for遍历当月时间
- v-for=”dayobject in days”
:key=”dayobject.index”
@click=”selectedDate(dayobject.day.getDate())”
>v-if=”dayobject.day.getMonth() + 1 != currentMonth”
class=”other-month”
>
{{ dayobject.day.getDate() }}
v-if=”
dayobject.day.getFullYear() == new Date().getFullYear() &&
dayobject.day.getMonth() == new Date().getMonth() &&
dayobject.day.getDate() == new Date().getDate()
“
class=”active”
>{{ dayobject.day.getDate() }} >
{{ dayobject.day.getDate() }}
如何判断一个月有多少天?
function getMonthDay(year, month) {
let days = new Date(year, month, 0).getDate()
return days
}
getMonthDay(2021, 3)