简单的vue日历组件

效果图

这里写图片描述
根据公司设计图制作了一个简单的日历组件,主要包括切换上一年、上一月、下一年、下一月,锁定开始时间、结束时间等功能,以上就是效果图。

用法

**html
<m-calendar :child="date0"></m-calendar>
<m-calendar :child="date1"></m-calendar>
**js
kim=new Vue({
    el:"#app",
    data:{
        date0:{
            now:"2017-11-05",
            end:"2017-11-25",
            callback:function(d){
                kim.date1.start=d;//两个组件间互相关联
            }
        },
        date1:{
            now:"2017-11-25",
            start:"2017-11-05",
            callback:function(d){
                kim.date0.end=d;
            }
        }
    }
});

主体部分

Vue.component("mCalendar",{
    props:["child"],
    data:function(){
   
        return {
            open:false,
            value:this.child.now,
            datatop:"",
            datalist:[],
            year:"",
            month:""
        }
    },
    methods:{
        showCalendar:function(){
   
            this.open=!this.open;
            if(this.open){
                if(this.value){
                    this.value=this.child.now.replace(/-/g,"/");
                }else{
                    this.value=new Date().getFullYear()+'/'+(Number(new Date().getMonth())+1)+'/'+new Date().getDate();
                };
                if(this.isDate()){
                    this.setDateInfo();
                };
            };
        },
        setDateInfo:function(dates){
    
            dates=dates||this.value;
            var Dates=new Date(dates);
            this.year=Dates.getFullYear
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值