国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

用vue寫一個日歷

瀏覽:5日期:2022-11-07 15:24:25

之前在上家公司做過一個公司人員考勤的東西,里面需要用到日歷,當時自己用vue隨便寫了一個,比較簡單,刪掉了其他功能的代碼,只留下日歷,直接看代碼

<template> <div class='lookForMonth_wrapper'> <div class='lookForMonth_top'> <div class='selectDate'> <div>{{year}} 年 {{month}} 月</div> <div class='upDownSelect'> <div @click='dateUp'></div> <div @click='dateDown'></div> </div> </div> </div> <div :style='calendarStyle'> <div v-for='(item,index) in calendarData' :key=’index’ :class='{ash:item.color===’ash’,date:index>6&&item.color!==’ash’}'> <p class='dateEdit'>{{item.label}}<i v-if='item.color!==’ash’&&index>=7'></i></p> <p v-if=’index>6’>上班</p> // 打工人 </div> </div> </div></template><script>export default { name: 'lookForMonth', data: () => { return { calendarData: [{label:'日'},{label: '一'}, {label:'二'},{label: '三'},{label: '四'},{label: '五'},{label: '六'}], //日歷循環渲染數據 year: 0, //當前日期年 month: 0, //當前日期月數 date: 0, //當前日期號數 day: -1, //當前星期幾 }; }, filters:{ }, computed: { // 根據當月日期詳情更改日歷表格高度 calendarStyle() { if (this.calendarData.length > 42) { return 'height: 701px;'; } else { return 'height: 601px;'; } } }, async created(){ // 獲取當前日期數據 this.getNow(); // 獲取當前月份一號的時間戳 let firstTime = +new Date(this.year,this.month-1,1,0,0,0) this.getCalendarDate(); // 給calendarData添加當月數據 }, mounted() { }, methods: { // 獲取當前時間 getNow() { let now = new Date() this.year = +now.getFullYear() this.month = +now.getMonth() + 1 this.date = +now.getDate() this.day = +now.getDay() }, // 獲取每個月的天數 monthDay(month) { if ([1,3,5,7,8,10,12].includes(month)) { return 31 } else if ([4,6,9,11].includes(month)) { return 30 } else if (month === 2) { // 判斷當年是否為閏年 if ( (this.year % 4 === 0 && this.year % 100 !== 0) || this.year % 400 === 0 ) { return 29 } else { return 28 } } }, // 給calendarData添加當月數據 getCalendarDate() { // 獲取當前月份一號星期幾 let firstDay = new Date(this.year + '-' + this.month + '-' + '01').getDay(); this.calendarData = [{label:'日'},{label: '一'}, {label:'二'},{label: '三'},{label: '四'},{label: '五'},{label: '六'}]; let num = parseInt(firstDay); let nowDays = this.monthDay(this.month); let lastMonth = this.month - 1>0?this.month - 1:12; let lastDays = this.monthDay(lastMonth); // 循環添加上一個月數據 for (let i = 0; i < num; i++) { this.calendarData.push({label:lastDays - num + i + 1,color:’ash’}); } // 循環添加當月數據 for (let i = 0; i < nowDays; i++) { this.calendarData.push({label:i + 1}); } // 循環添加下一個月數據 if (this.calendarData.length % 7 !== 0) { let surplusDay = 7 - (this.calendarData.length % 7); for (let i = 0; i < surplusDay; i++) { this.calendarData.push({label:i + 1,color:’ash’}); } } this.loading = false }, // 將日期調上 dateUp() { this.month--; if (this.month <= 0) { this.year--; this.month = 12; } this.getCalendarDate(); // 給calendarData添加當月數據 }, // 將日期調下 dateDown() { this.month++; if (this.month > 12) { this.year++; this.month = 1; } this.getCalendarDate(); // 給calendarData添加當月數據 }, }};</script><style lang='scss' scoped>.lookForMonth_wrapper { padding: 20px; width: 701px; margin: auto;}.lookForMonth_top { margin-bottom: 20px; overflow: hidden; .selectTeacher { float: left; } .selectDate { height: 30px; line-height: 30px; float: right; display: flex; .upDownSelect { display: flex; flex-direction: column; margin-top: -2px; margin-left: 5px; .upDownSelect_item { width: 0; height: 0; border: 7px solid transparent; cursor: pointer; } .upDownSelect_item:nth-child(1) { border-bottom: 7px solid #666; margin-bottom: 5px; &:hover { border-bottom: 7px solid skyblue; } } .upDownSelect_item:nth-child(2) { border-top: 7px solid #666; &:hover { border-top: 7px solid skyblue; } } } }}/* 日歷表樣式=======================================↓ */.calendar { width: 701px; border-top: 1px solid #ccc; border-left: 1px solid #ccc; display: flex; flex-wrap: wrap; box-sizing: border-box; .calendar_item { box-sizing: border-box; width: 100px; height: 100px; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; text-align: center; display: flex; flex-direction: column; justify-content: center; align-items: center; &.date:hover{ background: #eee; } .status{ margin-top: 10px; &.textBlue{ color: blue; } &.textRed{ color: brown; } } .el-icon-edit-outline{ cursor: pointer; margin-left: 7px; } } .ash{ color: gainsboro; } .dateEdit{ margin-bottom: 10px; }}</style>

效果如下:

用vue寫一個日歷

以上就是利用vue寫一個日歷的詳細內容,更多關于vue 日歷的資料請關注好吧啦網其它相關文章!

標簽: Vue
相關文章:
主站蜘蛛池模板: 国产精品露脸脏话对白 | 67194在线午夜亚洲 | 手机福利在线 | 国产精品一久久香蕉国产线看 | 精品视频一区二区三三区四区 | 久久精品国产免费看久久精品 | 欧美视频在线观看一区二区 | 99久久成人 | 日本不卡免费高清视频 | 久久精品毛片 | 狠狠综合久久久久综合 | 在线欧美色 | 国产成人精品日本亚洲网站 | 国产欧美综合精品一区二区 | 国产欧美日韩综合一区二区三区 | 亚洲一区免费在线观看 | 亚洲成 人a影院青久在线观看 | 亚洲精品国产一区二区三区在 | 日韩一级片播放 | 最新中文字幕一区二区乱码 | 波多野结衣视频在线观看地址免费 | 欧美极品大肚孕妇孕交 | 亚洲一区网站 | 国产欧美日韩在线观看一区二区三区 | 国产高清在线观看视频手机版 | 国产成人性色视频 | 欧美亚洲日本视频 | 亚洲一区二区三区四区在线观看 | 亚洲精品国产三级在线观看 | 亚洲成人www| 欧美videos另类齐全 | 亚洲夜夜爽 | 精品久久在线 | 欧美激情伦妇在线观看 | 精品无码久久久久久国产 | chinese农村野战videos | 拍拍拍又黄又爽无挡视频免费 | 国产20页| 草草在线观看视频 | 美女被cao免费看在线看网站 | 亚洲精品国产高清不卡在线 |