最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用vue寫一個日歷

 更新時間:2020年11月02日 14:07:33   作者:陳山豆  
這篇文章主要介紹了如何利用vue寫一個日歷,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下

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

<template>
 <div class="lookForMonth_wrapper">
  <div class="lookForMonth_top">
   <div class="selectDate">
    <div>{{year}} 年 {{month}} 月</div>
    <div class="upDownSelect">
     <div class="upDownSelect_item" @click="dateUp"></div>
     <div class="upDownSelect_item" @click="dateDown"></div>
    </div>
   </div>
  </div>
  <div class="calendar" :style="calendarStyle">
   <div v-for="(item,index) in calendarData" class="calendar_item" :key='index' :class="{ash:item.color==='ash',date:index>6&&item.color!=='ash'}">
    <p class="dateEdit">{{item.label}}<i class="el-icon-edit-outline" 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: "六"}], //日歷循環(huán)渲染數(shù)據(jù)
  year: 0, //當(dāng)前日期年
  month: 0, //當(dāng)前日期月數(shù)
  date: 0, //當(dāng)前日期號數(shù)
  day: -1, //當(dāng)前星期幾
 };
 },
 filters:{
 },
 computed: {
 // 根據(jù)當(dāng)月日期詳情更改日歷表格高度
 calendarStyle() {
  if (this.calendarData.length > 42) {
  return "height: 701px;";
  } else {
  return "height: 601px;";
  }
 }
 },
 async created(){
 // 獲取當(dāng)前日期數(shù)據(jù)
 this.getNow();
 // 獲取當(dāng)前月份一號的時間戳
 let firstTime = +new Date(this.year,this.month-1,1,0,0,0)
 this.getCalendarDate(); // 給calendarData添加當(dāng)月數(shù)據(jù)
 },
 mounted() {
 },
 methods: {
 // 獲取當(dāng)前時間
 getNow() {
  let now = new Date()
  this.year = +now.getFullYear()
  this.month = +now.getMonth() + 1
  this.date = +now.getDate()
  this.day = +now.getDay()
 },
 // 獲取每個月的天數(shù)
 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) {
  // 判斷當(dāng)年是否為閏年
  if (
   (this.year % 4 === 0 && this.year % 100 !== 0) ||
   this.year % 400 === 0
  ) {
   return 29
  } else {
   return 28
  }
  }
 },
 // 給calendarData添加當(dāng)月數(shù)據(jù)
 getCalendarDate() {
  // 獲取當(dāng)前月份一號星期幾
  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);
  // 循環(huán)添加上一個月數(shù)據(jù)
  for (let i = 0; i < num; i++) {
  this.calendarData.push({label:lastDays - num + i + 1,color:'ash'});
  }
  // 循環(huán)添加當(dāng)月數(shù)據(jù)
  for (let i = 0; i < nowDays; i++) {
  this.calendarData.push({label:i + 1});
  }
  // 循環(huán)添加下一個月數(shù)據(jù)
  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
 },
 // 將日期調(diào)上
 dateUp() {
  this.month--;
  if (this.month <= 0) {
  this.year--;
  this.month = 12;
  }
  this.getCalendarDate(); // 給calendarData添加當(dāng)月數(shù)據(jù)
 },
 // 將日期調(diào)下
 dateDown() {
  this.month++;
  if (this.month > 12) {
  this.year++;
  this.month = 1;
  }
  this.getCalendarDate(); // 給calendarData添加當(dāng)月數(shù)據(jù)
 },
 }
};
</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寫一個日歷的詳細(xì)內(nèi)容,更多關(guān)于vue 日歷的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • vue如何給element-ui中的el-tabs動態(tài)設(shè)置label屬性

    vue如何給element-ui中的el-tabs動態(tài)設(shè)置label屬性

    這篇文章主要介紹了vue如何給element-ui中的el-tabs動態(tài)設(shè)置label屬性,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue項目怎樣用nginx反向代理WebSocket請求地址

    vue項目怎樣用nginx反向代理WebSocket請求地址

    這篇文章主要介紹了vue項目怎樣用nginx反向代理WebSocket請求地址問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • 解決Element組件的坑:抽屜drawer和彈窗dialog

    解決Element組件的坑:抽屜drawer和彈窗dialog

    這篇文章主要介紹了解決Element組件的坑:抽屜drawer和彈窗dialog問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • vue-cli + sass 的正確打開方式圖文詳解

    vue-cli + sass 的正確打開方式圖文詳解

    本文通過圖文并茂的形式給大家介紹了vue-cli + sass 的正確打開方式,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-10-10
  • vue.js中mint-ui框架的使用方法

    vue.js中mint-ui框架的使用方法

    這篇文章主要為大家詳細(xì)介紹了vue.js中使用mint-ui框架的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • vue3觸發(fā)父組件兩種寫法

    vue3觸發(fā)父組件兩種寫法

    這篇文章主要介紹了vue3觸發(fā)父組件兩種寫法,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-08-08
  • Vue watch 偵聽對象屬性詳解

    Vue watch 偵聽對象屬性詳解

    Vue的watch偵聽器格式有兩種:方法格式和對象格式的偵聽器,這篇文章主要介紹了Vue watch 偵聽對象屬性相關(guān)知識,需要的朋友可以參考下
    2023-04-04
  • vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼

    vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼

    這篇文章主要介紹了vue中beforeRouteLeave實現(xiàn)頁面回退不刷新的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • vue實現(xiàn)頁面內(nèi)容禁止選中功能,僅輸入框和文本域可選

    vue實現(xiàn)頁面內(nèi)容禁止選中功能,僅輸入框和文本域可選

    今天小編就為大家分享一篇vue實現(xiàn)頁面內(nèi)容禁止選中功能,僅輸入框和文本域可選,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • vue組件中點擊按鈕后修改輸入框的狀態(tài)實例代碼

    vue組件中點擊按鈕后修改輸入框的狀態(tài)實例代碼

    要求點擊修改按鈕之后部分輸入框由禁用狀態(tài)變?yōu)榭捎脿顟B(tài)。下面我給大家分享一段實例代碼基于vue組件中點擊按鈕后修改輸入框的狀態(tài),需要的的朋友參考下
    2017-04-04

最新評論

沈丘县| 新源县| 通许县| 犍为县| 巴里| 德庆县| 兴化市| 康保县| 津南区| 霍州市| 泰来县| 尼勒克县| 永年县| 阳春市| 纳雍县| 渑池县| 潞城市| 明水县| 平顶山市| 桂林市| 东兰县| 乐至县| 鞍山市| 满城县| 博乐市| 儋州市| 兴安县| 神农架林区| 沅江市| 昌江| 栖霞市| 沙坪坝区| 亳州市| 宁南县| 灵川县| 女性| 渝中区| 海林市| 德江县| 那曲县| 固阳县|