vue平铺日历组件
vue日历自定义平铺组件
  <sy-icon  @click="preMon" class="copy-icon" iconClass="iconjiantou1"></sy-icon>  表示的是上一个月,是我自定的字体图标
  <sy-icon  @click="nextMon" class="copy-icon right-arrow" iconClass="iconjiantou1"></sy-icon>  表示的是下一个月,是我的自定义图标
<template>
    <div>
        <div class="header-title">
            <sy-icon  @click="preMon" class="copy-icon" iconClass="iconjiantou1"></sy-icon>
            <a class="data-now-a">{{currentYear}}/{{currentMonth+1}}</a>
            <sy-icon  @click="nextMon" class="copy-icon right-arrow" iconClass="iconjiantou1"></sy-icon>
        </div>
        <div class="flex-week">
            <a class="a-week" v-for="(item,index1) in listXIngqi" :key="index1">{{ item }}</a>
        </div>
        <ul class="date">
            <li v-for="(item, index) in list"  :key="index"
            @click="handerSelect(item)" class="riqili"
            :class="( Number(item.y+''+item.m+''+item.d)  >= Number(starttime)  && Number(endtime)  >= Number(item.y+''+item.m+''+item.d)  ||
            item.y+''+item.m+''+item.d == starttime||  item.y+''+item.m+''+item.d == endtime ) ? 'activeSelect' : ''"
           >
                <div class="day"   :class="{'text-color': item.cur}">
                    {{item.d}}
                    <a :class="item.y+''+item.m+''+item.d"></a>
                </div>
                <i class="current-day-cricle" v-if="item.y === year && item.m === month && item.d === day"></i>
            </li>
        </ul>
    </div>
</template>
<script>
    export default {
        data(){
            return{
                year: new Date().getFullYear(), // 今日年份
                month: new Date().getMonth() + 1, // 今日月份
                day: new Date().getDate(), // 今日日份
                currentYear: '', // 当前显示年份
                currentMonth: '', // 当前显示月份 0-11,显示时加一
                currentDay: '', // 当前显示日份
                monthDays: [], // 1-12月的天数
                list: [],
                listXIngqi:['一', '二', '三', '四', '五','六','日'],
                selectCompare:[],
                clickcount: 0, //点击次数
                starttime:'',//点击的开始的日期
                endtime:'', //点击的结束时间 数字
                params_starttime:'',//抛出去的参数
                params_endtime:'',//抛出去的参数
            }
        },
        mounted () {
            this.showCalender()
        },
        methods: {
            // 点击的日期
            handerSelect(mess){
                console.log(mess);
                if(mess.cur){
                    // 点击的是当前月
                    this.clickcount++;
                    if(this.clickcount % 2 == 1){
                        // 开始时间
                        this.starttime=mess.y+""+mess.m+""+mess.d;
                        this.endtime="";
                        this.params_starttime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d )
                        this.params_endtime="";
                   }else{
                        // 结束时间
                        this.endtime=mess.y+""+mess.m+""+mess.d;
                        this.params_endtime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d )
                       if(Number(this.starttime)>Number(this.endtime)){
                            this.endtime = Number(this.starttime);
                            this.params_endtime=this.params_starttime;
                            this.starttime = Number(mess.y+""+mess.m+""+mess.d);
                            this.params_starttime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d );
                        }
                    }
                    console.log('开始',this.starttime, this.params_starttime );
                    console.log('jieshu',this.endtime,  this.params_endtime  );
                    this.$emit('change',[this.params_starttime,this.params_endtime   ] )
                }else {
                    // if(mess.d>20){
                    //     this.nextMon();
                    // }else{
                    //     this.preMon();
                    // }
                }
            },
            isLeap (year) { // 判断是不是闰年
                return (year % 100 === 0 ? (year % 400 === 0 ? 1 : 0) : (year % 4 === 0 ? 1 : 0))
            },
            showCalender (type) {
                this.list = []
                this.newDate = new Date()
                if (!type) this.currentYear = this.newDate.getFullYear()
                if (!type) this.currentMonth = this.newDate.getMonth()
                    this.monthDays = [31, 28 + this.isLeap(this.currentYear), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
                    this.currentDay = this.newDate.getDate()
                    this.firstDay = new Date(`${this.currentYear}-${this.currentMonth + 1}-1`)
                    this.firstnow = this.firstDay.getDay() // 当月第一日是星期几 1-7
                    if (this.firstnow === 0) this.firstnow = 7
                    if (this.firstnow > 1) {
                        // 前一个月份
                        let monIndex = this.currentMonth
                        let year
                    if (monIndex === 0) {
                        year--
                        monIndex = 11
                    } else {
                        monIndex--
                    }
                    for (let i = 0; i < this.firstnow - 1; i++) {
                        this.list.unshift({
                            y: year,
                            m: monIndex + 1,
                            d: this.monthDays[monIndex] - i
                        })
                    }
                }
                for (let i = 0; i < this.monthDays[this.currentMonth]; i++) {
                    // 当前月份
                    this.list.push({
                        y: this.currentYear,
                        m: this.currentMonth + 1,
                        d: i + 1,
                        cur: true
                    })
                }
                const num = (this.monthDays[this.currentMonth] + this.firstnow - 1) % 7
                    if (num > 0) {
                    // 下个月份
                    let monIndex2 = this.currentMonth
                    let year2
                    if (monIndex2 === 11) {
                        year2++
                        monIndex2 = 0
                    } else {
                        monIndex2++
                    }
                    for (let i = 0; i < 7 - num; i++) {
                        this.list.push({
                        y: year2,
                        m: monIndex2 + 1,
                        d: i + 1
                        })
                    }
                }
        },
        clearData(){
            this.clickcount=0;
            this.starttime='';
            this.endtime='';
            this.params_starttime='';
            this.params_endtime='';
        },
        preMon () {
            this.clearData();
            if (this.currentMonth === 0) {
            this.currentYear--
            this.currentMonth = 11
            } else {
            this.currentMonth--
            }
            this.showCalender('pre')
        },
        nextMon () {
            this.clearData();
            if (this.currentMonth === 11) {
                this.currentYear++
                this.currentMonth = 0
            } else {
                this.currentMonth++
            }
            console.log( 'this.currentMonth',this.currentMonth );
            this.showCalender('next')
        }
    }
}
</script>
<style lang="scss" scoped>
.header-title{
    margin-right: 16px;
    height: 40px;
    opacity: 1;
    background: #f8f8f7;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    justify-content: space-between;
    padding-left: 16px;
    padding-right: 16px;
    margin-top: 16px;
    margin-bottom: 17px;
    .copy-icon{
        font-size: 20px;
        color: #71809c;
    }
    .data-now-a{
        font-size: 15px;
        font-family: Helvetica, Helvetica-Regular;
        font-weight: 400;
        color: rgba(0,0,0,0.85);
    }
    .right-arrow{
        transform: rotate(-180deg);
    }
}
.flex-week{
    display: flex;
    justify-content: space-between;
    padding-right: 37px;
    padding-left: 21px;
    .a-week{
        font-size: 14px;
        font-family: Helvetica, Helvetica-Regular;
        font-weight: 400;
        text-align: center;
        color: #253f50;
        display: inline-block;
        width: 40px;
        height: 30px;
    }
}
.date{
  display: flex;
  justify-content: flex-start;
  flex-wrap: wrap;
  align-items: center;
  padding-left: 20px;
  padding-right: 36px;
    .riqili{
        height: 40px;
        width: 40px;
        display: flex;
        // 末尾或者上月天数颜色
        justify-content: center;
        align-items: center;
        color: #b8bfce;
        font-size: 12px;
        margin-bottom: 10px;
        position: relative;
        margin-right: 3px;
    //当前月的正常颜色
    .text-color{
        font-size: 14px;
        font-family: Helvetica, Helvetica-Regular;
        font-weight: 400;
        text-align: center;
        color: #72809e;
    }
    // 当月当天的标识
    .current-day-cricle{
        display: block;
        width: 5px;
        height: 5px;
        background: #28ae61;
        border-radius: 50%;
        position: absolute;
        bottom: 6px;
        left: 17px;
    }
  }
   .riqili:nth-child(4n){
       margin-right: 5px;
   }
   .riqili:nth-child(7n){
       margin-right: 0px;
   }
}
.activeSelect{
    width: 40px;
    height: 40px;
    opacity: 1;
    background: #3b8bfa;
    border-radius: 50%;
    .day{
        color: #fff !important;
    }
}
</style>
在页面中直接使用就可以了
<calendar-data @change="changeSelect"></calendar-data>
//arr是你选择的开始日期和结束日期
changeSelect(arr){
    this.timeArrStartAndEnd=arr;
},


参考的地址:https://www.cnblogs.com/xue-wejie/p/10553291.html
vue平铺日历组件的更多相关文章
- Vue文件封装日历组件
		封装就是要具有灵活性,样式自适应,调用的时候传入props就可以变成自己想要的样式. 效果展示网址:https://1963331542.github.io/ 源代码: <template> ... 
- 基于Vue的简单日历组件
		日历组件 由于移动端项目中需要用到日历组件,网上找了下,没看到几个合适的,就尝试着自己写一个.然后发现也不是很复杂,目前只做了最基本的功能,大家也可以拿去做做二次开发. 如何写一个日历组件 基础效果如 ... 
- Flutter——ListView组件(平铺列表组件)
		ListView的常见参数: 名称 类型 说明 scrollDirection Axis Axis.horizontal 水平列表 Axis.vertical 垂直列表 padding EdgeIns ... 
- 如何用vue封装一个防用户删除的平铺页面的水印组件
		需求 为了防止截图等安全问题,在web项目页面中生成一个平铺全屏的水印 要求水印内容为用户名,水印节点用户不能通过开发者工具等删除 效果 如上图 在body节点下插入水印DOM节点,水印节点覆盖在页面 ... 
- vue初学实践之路——vue简单日历组件(1)
		---恢复内容开始--- 最近做的项目有一个需求,需要有一个日历组件供预定功能使用,之前的代码过于繁琐复杂,所以我采用vue重写了这个组件. npm.vue等等安装. 只是一个简单的日历组件,所以并不 ... 
- vue-calendar 基于 vue 2.0 开发的轻量,高性能日历组件
		vue-calendar-component 基于 vue 2.0 开发的轻量,高性能日历组件 占用内存小,性能好,样式好看,可扩展性强 原生 js 开发,没引入第三方库 Why Github 上很多 ... 
- Vue自定义日历组件
		今天给大家介绍Vue的日历组件,可自定义样式.日历类型及支持扩展,可自定义事件回调.Props数据传输. 线上demo效果 示例 Template: <Calendar :sundayStart ... 
- 一个vue的日历组件
		说明: 1.基于element-ui开发的vue日历组件. 地址 更新: 1.增加value-format指定返回值的格式2.增加头部插槽自定义头部 <ele-calendar > < ... 
- 使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换
		使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换 需求: 日历区分交易日.非交易日 可以切换面板查看整年交易日信息 可以在手动调整交易日.非交易日 演示实例 序--使用软 ... 
- vue之手把手教你写日历组件
		---恢复内容开始--- 1.日历组件 1.分析功能:日历基本功能,点击事件改变日期,样式的改变 1.结构分析:html 1.分为上下两个部分 2.上面分为左按钮,中间内容展示,右按钮 下面分为周几展 ... 
随机推荐
- MindSpore-2.4版本中的一些新特性
			技术背景 在前面的一篇博客中我们介绍了MindSpore-2.4-gpu的安装和其中可能出现的一些问题.这里我们在安装完成之后,可以尝试使用一些MindSpore新版本的特性.那么在安装之后,如果是使 ... 
- Nuxt.js 应用中的 webpack:compiled 事件钩子
			title: Nuxt.js 应用中的 webpack:compiled 事件钩子 date: 2024/11/23 updated: 2024/11/23 author: cmdragon exce ... 
- 基于Spring源码分析AOP的实现机制
			Spring一个重要的特性就是提供了AOP,使得我们可以在原有的基础上增加我们自己的系统业务逻辑.使得我们系统业务逻辑与应用业务逻辑相分离,耦合性降低,并且大大的提高了开发的效率.Spring的AOP ... 
- 解决GitHub无法访问问题
			作为开发者,经常使用借助GitHub进行开发,但是最近一直无法访问github.com站点,决定搞一下!!! 由于国内某些原因,导致我们有时候不能访问到 www.github.com.此时我们必须找到 ... 
- 三菱电梯综合监控系统适配 lonele.exe 由 20180418 降级至 20150930 而调整相应的 msde2000 数据库
			win10 x86 系统下程序文件的部分目录可能是 电梯综合监控系统 C:\PROGRAM FILES\上海三菱电梯有限公司 ├─电梯综合监控系统 │ │ AxInterop.BRTMFSHX.dll ... 
- HashMap 源码解毒
			PUT 方法解毒: hashcode 高低16进行异或运算,尽量降低哈希冲突的概率 如果数组很小,hashcode的高位就不能被很好利用. final V putVal(int hash, K key ... 
- CVE-2023-48409 Mali GPU 整数溢出导致堆越界写
			CVE-2023-48409 Mali GPU 整数溢出导致堆越界写 https://github.com/0x36/Pixel_GPU_Exploit 漏洞原语:假设分配的大小为 0x3004, ... 
- 恭喜您获得【智能工具箱】,使用后图片大小-80%、视频大小-90%、PPT附带在线预览属性…
			小梁是一名小学英语老师,因为疫情影响,全市中小学都要求师生居家进行线上教学.学习.因为线上教学的各种局限性,为保证教学质量,学校要求老师们提前录制好课程,在上课时播放录制课程,老师自己需要在一旁进行线 ... 
- 【数据库】MySQL概念性基础知识期末复习
			选择题 第一章 3 二维表结构--数据模型--关系数据模型 5 描述全部数据整体逻辑结构--模式 6 逻辑数据独立性--模式变,外模式和应用程序不变 7 物理数据独立性--内模式变,外模式和应用程序不 ... 
- 【转载】 Spring Security做JWT认证和授权
			https://www.jianshu.com/p/d5ce890c67f7 上一篇博客讲了如何使用Shiro和JWT做认证和授权(传送门:https://www.jianshu.com/p/0b11 ... 
