这是在工作的时候做的一个考勤日历功能,整体来说比较简单,记录在此,方便以后复盘
用到的组件有moment.js,有这个组件大大简化了一些时间的加减计算
先上整体效果:
ps:样式有点丑,没做调整
1.首先是HTML结构部分
<div style="width: 500px;height: 500px;">
<!-- 标题、上月、下月-->
<div class="width-100-per layout-side" style="height: 10%;">
<div class="cursor-pointer layout-center leftRightBtn" @click="prevMonth"><</div>
<div class="height-100-per layout-center-top width-40-per">
<div class="layout-center timeTitle">
<span style="font-weight: bold">{
{
`${
newDate.split('-')[0]}年${
newDate.split('-')[1]}月`}}</span>
</div>
</div>
<div class="cursor-pointer layout-center leftRightBtn" @click="nextMonth">></div>
</div>
<!-- 日期表-->
<div class="width-100-per layout-left-top padding-10-px" style="height: calc(100% - 10%)">
<!-- 星期-->
<div class="width-100-per layout-left-top" style="height: 10%">
<div style="width: calc(100% / 7);" class="layout-center" v-for="(i,index) in weekArr" :key="index + i">{
{
i}}
</div>
</div>
<!-- 日期-->
<div class="width-100-per layout-left-top" style="height: 90%">
<template v-for=