---恢复内容开始---

1.日历组件

1.分析功能:日历基本功能,点击事件改变日期,样式的改变

1.结构分析:html

1.分为上下两个部分

2.上面分为左按钮,中间内容展示,右按钮

下面分为周几展示和日期展示

3.基本结构页面html书写

<template>
   <div class="calender2">
       <div class="date-header">
           <div class="pre-month"></div>
           <div class="show-date">2019年8月9日</div>
           <div class="next-month"></div>
       </div>
       <div class="date-content">
           <div class="week-header">
               <div
               v-for="item in ['日','一','二','三','四','五','六']"
               :key= item
               >{{ item }}</div>
           </div>
           <div class="week-day">
               <div
               class="every-day"
               v-for="item in 42"
               :key="item"
               >{{ item }}</div>
           </div>
       </div>
   </div>
</template>
*{
   margin: 0px;
   border: 0px;
   list-style: none;
}
.calender2{
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%,-50%);
   height:380px;
   width:420px;
   border: 1px solid #ccc;
}
.date-header{
   margin-left: 10px;
   height: 40px;
   width: 350px;
   line-height: 40px;
   text-align: center;
}
.pre-month{
   position: absolute;
   display: inline-block;
   height: 0px;
   width:0px;
   border:20px solid ;
   border-color: transparent rgb(35, 137, 206) transparent transparent;
}
.next-month{
   position: absolute;
   display: inline-block;
   height: 0px;
   width:0px;
   border:20px solid ;
   border-color: transparent transparent transparent  rgb(35, 137, 206);
}
.show-date{
   margin-left: 40px;
   margin-top: 0px;
   display: inline-block;
   line-height: 40px;
   text-align: center;
   width: 310px;
   color: rgb(35, 137, 206);
}
.week-header{
   background: rgb(35, 137, 206);
   color: #fff;
   font-size: 14px;
   text-align: center;
   line-height: 20px;
}
.week-header div{
   margin: 0;
   padding: 0;
   display: inline-block;
   height: 20px;
   width: 60px;
}
.every-day{
   display: inline-block;
   height: 50px;
   width: 60px;
   text-align: center;
   line-height: 50px;
}
.other-day{
   color: #ccc;
}
.now-day{
   background: rgb(35, 137, 206);
}
.active-day{
   /* padding: 2px */
   /* border-sizing:content-box; */
   border: 2px solid rgb(35, 137, 206);
}
</style>

4.一些事件以及逻辑

1.使得当前的日期为今天的日期

            <div class="show-date">{{ year }}年{{ month }}月{{ day }}日</div>
data(){
       return{
           year:null,
           month:null,
           day:null
      }
  },
   created(){
       this.getInitDate();
  },
   methods:{
       getInitDate(){
           const date = new Date();
           this.year = date.getFullYear();
           this.month = date.getUTCMonth() + 1;
           this.day = date.getDate();
      }
  }

2.设置该月日期起始值(找到一号是在哪里)

beginDay(){
return new Date(this.year, this.mounth - 1, 1).getDay();
}

3.当月天数字体正常显示

<div 
v-if="item - beginDay >= 0 && item - beginDay <= curDays"
>{{ item - beginDay }}</div>

4.当月天数之前的部分变灰,外加正常显示日期

注意几个数学问题:

1.当前月天数日期
2.上月剩余天数
3.此月显示的下月天数
<div 
    v-if="item - beginDay > 0 && item - beginDay <= curDays"
    >{{ item - beginDay }}</div>
<div
    class="other-day"
    v-else-if="item - beginDay <= 0"
    >{{ item - beginDay + prevDays }}</div>
<div
    class="other-day"
    v-else>{{ item - beginDay -curDays }}</div>

5.能知道当前日期,能点击其他日期,并且会有相应的变化

知道当前日期:

 this.curDate = `${this.year}-${this.month}-${this.day}`

判断今天是不是当前日期,并且给一个样式:

'now-day':`${year}-${month}-${item - beginDays}` == curDate

当点击当月有的日期的时候会根据你的点击显示的日期发生变化

判断是点击的那一天:

'active-day':`${year}-${month}-${item - beginDay}` === `${year}-${month}-${day}`

点击这一天,绑定点击事件

@click="handleClickDay(item - beginDay)"
handleClickDay(day){
this.day = day
}

6.前后两个按钮的功能

            <div class="pre-month" @click="handlePrev"></div>
           <div class="next-month" @click="handleNext"></div>
handlePrev(){
           if(this.month == 1){
               this.month = 12
               this.year--
          }else{
               this.month--
          }
      },
       handleNext(){
           if(this.month == 12){
               this.month = 1
               this.year++
          }else{
               this.month++
          }
      }

7.判断点击的是否为当月的最后一天

computedDay(){
           const allDay = new Date(this.year, this.month, 0).getDate();
           if(this.day > allDay){
               this.day = allDay;
          }
      }

将这个函数分别在handlePrev(),handleNext()里面执行-------注意是this.computedDay();

完成

---恢复内容结束---

1.日历组件

1.分析功能:日历基本功能,点击事件改变日期,样式的改变

1.结构分析:html

1.分为上下两个部分

2.上面分为左按钮,中间内容展示,右按钮

下面分为周几展示和日期展示

3.基本结构页面html书写

<template>
   <div class="calender2">
       <div class="date-header">
           <div class="pre-month"></div>
           <div class="show-date">2019年8月9日</div>
           <div class="next-month"></div>
       </div>
       <div class="date-content">
           <div class="week-header">
               <div
               v-for="item in ['日','一','二','三','四','五','六']"
               :key= item
               >{{ item }}</div>
           </div>
           <div class="week-day">
               <div
               class="every-day"
               v-for="item in 42"
               :key="item"
               >{{ item }}</div>
           </div>
       </div>
   </div>
</template>
*{
   margin: 0px;
   border: 0px;
   list-style: none;
}
.calender2{
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%,-50%);
   height:380px;
   width:420px;
   border: 1px solid #ccc;
}
.date-header{
   margin-left: 10px;
   height: 40px;
   width: 350px;
   line-height: 40px;
   text-align: center;
}
.pre-month{
   position: absolute;
   display: inline-block;
   height: 0px;
   width:0px;
   border:20px solid ;
   border-color: transparent rgb(35, 137, 206) transparent transparent;
}
.next-month{
   position: absolute;
   display: inline-block;
   height: 0px;
   width:0px;
   border:20px solid ;
   border-color: transparent transparent transparent  rgb(35, 137, 206);
}
.show-date{
   margin-left: 40px;
   margin-top: 0px;
   display: inline-block;
   line-height: 40px;
   text-align: center;
   width: 310px;
   color: rgb(35, 137, 206);
}
.week-header{
   background: rgb(35, 137, 206);
   color: #fff;
   font-size: 14px;
   text-align: center;
   line-height: 20px;
}
.week-header div{
   margin: 0;
   padding: 0;
   display: inline-block;
   height: 20px;
   width: 60px;
}
.every-day{
   display: inline-block;
   height: 50px;
   width: 60px;
   text-align: center;
   line-height: 50px;
}
.other-day{
   color: #ccc;
}
.now-day{
   background: rgb(35, 137, 206);
}
.active-day{
   /* padding: 2px */
   /* border-sizing:content-box; */
   border: 2px solid rgb(35, 137, 206);
}
</style>

4.一些事件以及逻辑

1.使得当前的日期为今天的日期

            <div class="show-date">{{ year }}年{{ month }}月{{ day }}日</div>
data(){
       return{
           year:null,
           month:null,
           day:null
      }
  },
   created(){
       this.getInitDate();
  },
   methods:{
       getInitDate(){
           const date = new Date();
           this.year = date.getFullYear();
           this.month = date.getUTCMonth() + 1;
           this.day = date.getDate();
      }
  }

2.设置该月日期起始值(找到一号是在哪里)

beginDay(){
return new Date(this.year, this.mounth - 1, 1).getDay();
}

3.当月天数字体正常显示

<div 
v-if="item - beginDay >= 0 && item - beginDay <= curDays"
>{{ item - beginDay }}</div>

4.当月天数之前的部分变灰,外加正常显示日期

注意几个数学问题:

1.当前月天数日期
2.上月剩余天数
3.此月显示的下月天数
<div 
    v-if="item - beginDay > 0 && item - beginDay <= curDays"
    >{{ item - beginDay }}</div>
<div
    class="other-day"
    v-else-if="item - beginDay <= 0"
    >{{ item - beginDay + prevDays }}</div>
<div
    class="other-day"
    v-else>{{ item - beginDay -curDays }}</div>

5.能知道当前日期,能点击其他日期,并且会有相应的变化

知道当前日期:

 this.curDate = `${this.year}-${this.month}-${this.day}`

判断今天是不是当前日期,并且给一个样式:

'now-day':`${year}-${month}-${item - beginDays}` == curDate

当点击当月有的日期的时候会根据你的点击显示的日期发生变化

判断是点击的那一天:

'active-day':`${year}-${month}-${item - beginDay}` === `${year}-${month}-${day}`

点击这一天,绑定点击事件

@click="handleClickDay(item - beginDay)"
handleClickDay(day){
this.day = day
}

6.前后两个按钮的功能

            <div class="pre-month" @click="handlePrev"></div>
           <div class="next-month" @click="handleNext"></div>
handlePrev(){
           if(this.month == 1){
               this.month = 12
               this.year--
          }else{
               this.month--
          }
      },
       handleNext(){
           if(this.month == 12){
               this.month = 1
               this.year++
          }else{
               this.month++
          }
      }

7.判断点击的是否为当月的最后一天

computedDay(){
           const allDay = new Date(this.year, this.month, 0).getDate();
           if(this.day > allDay){
               this.day = allDay;
          }
      }

将这个函数分别在handlePrev(),handleNext()里面执行-------注意是this.computedDay();

完成

vue之手把手教你写日历组件的更多相关文章

  1. [原创]手把手教你写网络爬虫(4):Scrapy入门

    手把手教你写网络爬虫(4) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 上期我们理性的分析了为什么要学习Scrapy,理由只有一个,那就是免费,一分钱都不用花! 咦?怎么有人扔西红柿 ...

  2. [原创]手把手教你写网络爬虫(5):PhantomJS实战

    手把手教你写网络爬虫(5) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 大家好!从今天开始,我要与大家一起打造一个属于我们自己的分布式爬虫平台,同时也会对涉及到的技术进行详细介绍.大 ...

  3. 手把手教你写Kafka Streams程序

    本文从以下四个方面手把手教你写Kafka Streams程序: 一. 设置Maven项目 二. 编写第一个Streams应用程序:Pipe 三. 编写第二个Streams应用程序:Line Split ...

  4. 手把手教你写DI_0_DI是什么?

    DI是什么? Dependency Injection 常常简称为:DI. 它是实现控制反转(Inversion of Control – IoC)的一个模式. fowler 大大大神 "几 ...

  5. 手把手教你写Sublime中的Snippet

    手把手教你写Sublime中的Snippet Sublime Text号称最性感的编辑器, 并且越来越多人使用, 美观, 高效 关于如何使用Sublime text可以参考我的另一篇文章, 相信你会喜 ...

  6. 手把手教你写LKM rookit! 之 第一个lkm程序及模块隐藏(一)

    唉,一开始在纠结起个什么名字,感觉名字常常的很装逼,于是起了个这<手把手教你写LKM rookit> 我觉得: 你们觉得:...... 开始之前,我们先来理解一句话:一切的操作都是系统调用 ...

  7. 手把手教你写电商爬虫-第三课 实战尚妆网AJAX请求处理和内容提取

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 看完两篇,相信大家已经从开始的 ...

  8. 手把手教你写电商爬虫-第四课 淘宝网商品爬虫自动JS渲染

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 手把手教你写电商爬虫-第三课 ...

  9. 只有20行Javascript代码!手把手教你写一个页面模板引擎

    http://www.toobug.net/article/how_to_design_front_end_template_engine.html http://barretlee.com/webs ...

随机推荐

  1. 统计学习方法9—EM算法

      EM算法是一种迭代算法,是一种用于计算包含隐变量概率模型的最大似然估计方法,或极大后验概率.EM即expectation maximization,期望最大化算法. 1. 极大似然估计   在概率 ...

  2. CentOS 网络互通情况下把一个Linux服务器的文件发送到另一个服务器

    scp -r  文件名/目录名 root@192.168.2.144:/home/hsw -r   发送目录使用,表示把该目录下的所有子目录以及文件发送过去

  3. 我在工作中遇到的redis集群使用

    写次随笔,给自己工作学习中记录一个笔记 废话不多说,直接上代码: 功能:将相关信息存到redis中,并设置过期时间,如果redis中有,从redis获取,如果没有,从mysql中获取.redis配置了 ...

  4. 不使用 ASR 将虚机还原到另一个数据中心

    背景 在 Azure 上可能会遇到一个场景是将一台虚机搬到另一台数据中心,在不借助 ASR 的情况下我们该如何做? 因为 ASR 在云上更多的场景是用于灾备到异地.对于虚机的相关信息主要的是磁盘和网络 ...

  5. 工具资源系列之给 windows 虚拟机装个 mac

    众说周知,Mac 很好但也很贵,对一般大众而言,漂亮简洁高颜值,对软件开发者而言,方便省心有点贵. 好到什么程度? 内置大量常用的开发工具,省去了初学者安装配置环境的麻烦,版本控制工具 svn 默认已 ...

  6. JAVA开发第一步 - JDK安装与配置

    JDK的安装与环境变量配置是JAVA开发之路的第一步,很多新人在这一步上就卡了很久,浪费了很多时间,甚至有些人就轻易地“从入门到放弃”了.今天我们就来一步步教你如何打倒这第一只拦路虎. 1.JDK下载 ...

  7. 控制反转&依赖注入

    IoC(Inversion of Control,控制反转).这是spring的核心,贯穿始终.所谓IoC,对于spring框架来说,就是由spring来负责控制对象的生命周期和对象间的关系.这是什么 ...

  8. NOIP 2004 虫食算题解

    问题 E: [Noip2004]虫食算 时间限制: 1 Sec  内存限制: 128 MB 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一 ...

  9. MyBatis从入门到精通:使用XML方式(映射文件之类的)

    2.3节笔记部分: package tk.mybatis.simple; public class Temp { } /* 2.2 使用XML方式 MyBatis使用了Java的动态代理可以直接通过接 ...

  10. 个人永久性免费-Excel催化剂功能第22波-Excel文件类型、密码批量修改,补齐PowerQuery短板

    Excel的多工作薄.多工作表批量合并功能,Excel用户很多这方面的使用场景,也促使了各大Excel各大插件们都在此功能上有所开发,体验程度不一,但总体能够满足大多数的应用场景,本人之前也开发个单独 ...