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

vue實現(xiàn)自定義日期組件功能的實例代碼

 更新時間:2018年11月06日 14:01:53   作者:kristy1993  
這篇文章主要介紹了vue自定義日期組件的實現(xiàn)代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

實現(xiàn)一個日期組件,如圖:


components.js代碼如下:

Vue.component('sc-calendar',{
  template:'<div class="scCalendar">' +
  '<div class="calendar_header">' +
    '<div class="prev" @click="prevMonth"> < </div>' +
    '<span class="text_year">{{currentYear}}年</span>' +
    '<span class="text_month">{{currentMonth}}月</span>' +
    '<div class="next" @click="nextMonth"> > </div>' +
  '</div>' +
  '<div class="calendar_content">' +
    '<ul class="week">' +
      '<li v-for="item in weeks">{{item}}</li>' +
    '</ul>' +
    '<ul class="day">' +
      '<li v-for="item in dayList" :class="{marginRight0:item.marginRight0}">{{item.text}}</li>' +
    '</ul>' +
  '</div>' +
  '</div>',
  data:function(){
    return {
      weeks: ['日', '一', '二', '三', '四', '五', '六'],
      dayList:[],
      currentYear:'',
      currentMonth: ''
    }
  },
  created:function(){
    var date=new Date;
    this.currentYear = date.getFullYear();
    this.currentMonth = date.getMonth()+1;
    this.calDay(this.currentYear, this.currentMonth);
  },
  methods:{
    //計算指定月份的天數(shù)
    calDay:function(year,month){
      var oDate = new Date();
      //setFullYear(year,month,day) 方法用于設(shè)置年份,返回調(diào)整過的日期的毫秒表示。
      oDate.setFullYear(year, month-1,1);
      oDate.setDate(1);//設(shè)置一個月中的第一天
      var oNow = oDate.getDay();//當前月的第一天是星期幾
      var dayNum = 0; //指定月份的天數(shù)
      if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
        dayNum = 31;
      }else if(month==4 || month==6 || month==9 || month==11){
        dayNum = 30;
      }else if(month==2&&this.isLeaYear(year)){
        dayNum = 29;
      }else{
        dayNum = 28;
      }
      var SumDayLiNum = 0;//總共的格子數(shù)
      var lastNum = (dayNum-(7-oNow))%7; //最后剩余的數(shù)
      lastNum = lastNum == 0?0:7;
      SumDayLiNum = 7 + parseInt((dayNum-(7-oNow))/7)*7+lastNum;
      this.showDayList(dayNum,SumDayLiNum,oNow);
    },
    //判斷是否是閏年
    isLeaYear:function(year){
      if(year%4==0&&year%100!=0){
        return true;
      }else{
        if(year%400==0){
          return true;
        }else{
          return false;
        }
      }
    },
    //顯示當前日歷內(nèi)容
    showDayList:function(dayNum,SumDayLiNum,oNow){
      this.dayList = [];
      var rows = parseInt(SumDayLiNum/7);
      var cols = 7;
      for(var i=0;i<rows;i++){
        for(var j=0;j<cols ;j++){
          if(j == cols-1){
            this.dayList.push({
              text:'',
              marginRight0:true
            })
          }else{
            this.dayList.push({
              text:'',
              marginRight0:false
            })
          }
        }
      }
      for(var z=1;z<=dayNum;z++){
        this.dayList[oNow].text = z;
        oNow++;
      }
    },
    prevMonth:function(){
      if( this.currentMonth == 1){
        this.currentYear = this.currentYear - 1;
        this.currentMonth = 12;
      }else{
        this.currentMonth = this.currentMonth - 1;
      }
      this.calDay(this.currentYear, this.currentMonth);
    },
    nextMonth:function(){
      if( this.currentMonth == 12){
        this.currentYear = this.currentYear + 1;
        this.currentMonth = 1;
      }else{
        this.currentMonth = this.currentMonth + 1;
      }
      this.calDay(this.currentYear, this.currentMonth);
    }
  }
});

ccal.css代碼:

html {
 font-family: '微軟雅黑';
}
body,
div,
span,
img,
ul,
li,
p {
 margin: 0;
 padding: 0;
}
ul,
li {
 list-style: none;
}
.commonprev {
 width: 0.46666667rem;
 height: 0.93333333rem;
 color: #ffffff;
 position: absolute;
 display: inline-block;
}
.commonyear {
 width: 5.46666667rem;
 height: 1.6rem;
 font-size: 1rem;
 color: #ffffff;
 position: absolute;
}
.scCalendar {
 width: 25rem;
 height: 21.66666667rem;
 background: #005498;
 background-size: 100%;
}
.scCalendar .calendar_header {
 height: 2.93333333rem;
 width: 100%;
 position: relative;
 line-height: 2.93333333rem;
}
.scCalendar .calendar_header .prev {
 width: 0.46666667rem;
 height: 0.93333333rem;
 color: #ffffff;
 position: absolute;
 display: inline-block;
 left: 2.76666667rem;
}
.scCalendar .calendar_header .next {
 width: 0.46666667rem;
 height: 0.93333333rem;
 color: #ffffff;
 position: absolute;
 display: inline-block;
 right: 2.76666667rem;
}
.scCalendar .calendar_header .text_year {
 width: 5.46666667rem;
 height: 1.6rem;
 font-size: 1rem;
 color: #ffffff;
 position: absolute;
 left: 9.76666667rem;
}
.scCalendar .calendar_header .text_month {
 width: 5.46666667rem;
 height: 1.6rem;
 font-size: 1rem;
 color: #ffffff;
 position: absolute;
 left: 13.1rem;
}
.scCalendar .calendar_content {
 padding: 0 1rem;
}
.scCalendar .calendar_content li {
 width: 2rem;
 height: 2rem;
 line-height: 2rem;
 margin-right: 1.5rem;
 text-align: center;
 margin-bottom: 0.66666667rem;
 float: left;
 color: white;
 font-size: 0.93333333rem;
}
.scCalendar .calendar_content .week li:nth-of-type(7) {
 margin-right: 0;
}
.scCalendar .calendar_content .day .marginRight0 {
 margin-right: 0;
}

index.html代碼:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="./ccal.css" rel="external nofollow" >
  <script>
    var pixRatio = 1/window.devicePixelRatio; //像素比
    var html = document.documentElement;
    document.write('<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale='+ pixRatio +',minimum-scale='+ pixRatio +',maximum-scale='+ pixRatio +'">');
    html.style.fontSize = html.clientWidth/25 + 'px';
  </script>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
  <script src="./components.js"></script>
</head>
<body>
<div id="app">
  <div class="calendar">
    <sc-calendar></sc-calendar>
  </div>
</div>
</body>
<script>
  var vm = new Vue({
    el:'#app'
  })
</script>
</html>

總結(jié)

以上所述是小編給大家介紹的vue實現(xiàn)自定義日期組件功能的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • vue.js實現(xiàn)照片放大功能

    vue.js實現(xiàn)照片放大功能

    這篇文章主要為大家詳細介紹了vue.js實現(xiàn)照片放大功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • Vue解決echart在element的tab切換時顯示不正確問題

    Vue解決echart在element的tab切換時顯示不正確問題

    這篇文章主要介紹了Vue解決echart在element的tab切換時顯示不正確問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • 基于vue中css預加載使用sass的配置方式詳解

    基于vue中css預加載使用sass的配置方式詳解

    下面小編就為大家分享一篇基于vue中css預加載使用sass的配置方式詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • 深入了解Vue中雙向數(shù)據(jù)綁定原理

    深入了解Vue中雙向數(shù)據(jù)綁定原理

    vue是一個mvvm框架,即數(shù)據(jù)雙向綁定,即當數(shù)據(jù)發(fā)生變化的時候,視圖也就發(fā)生變化,當視圖發(fā)生變化的時候,數(shù)據(jù)也會跟著同步變化。本文將通過示例詳解其中原理,需要的可以參考一下
    2022-05-05
  • vue el-upload上傳文件的示例代碼

    vue el-upload上傳文件的示例代碼

    這篇文章主要介紹了vue el-upload上傳文件的示例代碼,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-12-12
  • vue如何加載本地json數(shù)據(jù)

    vue如何加載本地json數(shù)據(jù)

    這篇文章主要介紹了vue如何加載本地json數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue項目部署自動清除緩存方式

    vue項目部署自動清除緩存方式

    這篇文章主要介紹了vue項目部署自動清除緩存方式,包括清除文件緩存,清除瀏覽器 localStorage 緩存方式,本文結(jié)合示例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2023-07-07
  • vue中后端做Excel導出功能返回數(shù)據(jù)流前端的處理操作

    vue中后端做Excel導出功能返回數(shù)據(jù)流前端的處理操作

    這篇文章主要介紹了vue中后端做Excel導出功能返回數(shù)據(jù)流前端的處理操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 詳解Vue中watch的詳細用法

    詳解Vue中watch的詳細用法

    在vue中,使用watch來響應數(shù)據(jù)的變化。watch的用法大致有三種。下面代碼是watch的一種簡單的用法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-11-11
  • Vue2 添加數(shù)據(jù)可視化支持的方法步驟

    Vue2 添加數(shù)據(jù)可視化支持的方法步驟

    這篇文章主要介紹了Vue2 添加數(shù)據(jù)可視化支持的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01

最新評論

且末县| 三台县| 盈江县| 栖霞市| 孟连| 玉屏| 亳州市| 梁平县| 鄯善县| 永新县| 屯门区| 绩溪县| 萝北县| 大同市| 扎鲁特旗| 台安县| 马鞍山市| 新龙县| 宜宾市| 沐川县| 金华市| 眉山市| 柘城县| 延边| 太白县| 新绛县| 鹰潭市| 开江县| 英德市| 吉水县| 丹东市| 从化市| 和林格尔县| 神农架林区| 九台市| 蒙自县| 长兴县| 五华县| 石狮市| 蒲城县| 曲周县|