【calendar日历组件】elementul的日历组件点击拿到对应的日期或者触发某些事件

elementul的日历组件文档没有写方法,文档很少,很多人一开始看是懵的。所以记录一下做法

图片

在这里插入图片描述

代码

思路:通过监听value的变化拿到对应的日期,同时可以根据这个监听触发对应的方法。

<template>
  <el-calendar v-model="value" id="calendar">
      <template
       slot="dateCell"
       slot-scope="{data}">
        <!--自定义内容-->
          <div>
             <div class="calendar-day" >{{ data.day.split('-').slice(2).join('-') }}</div>
          </div>
      </template>
</el-calendar>
</template>
 
<script>
    export default {
        name: "calendar",
        data(){
            return {
                value: new Date()
            }
        },
        watch: {
            value: function() {
                var year = this.value.getFullYear();
                var month = this.value.getMonth() + 1;
                var date=this.value.getDate()
                if (date >= 1 && date <= 9) {//日如果小于10就补个0
                    date = "0" + date;
                }
                if (month >= 1 && month <= 9) {//月如果小于10就补个0
                    month = "0" + month;
                }
                console.log(year + '-' + month + '-' + date) // 打印出日历选中了哪年哪月
                this.getCalendarList()   //  调用接口,把拼接好的参数传到后台
            }
        },
        methods:{
          getCalendarList(){
            console.log('接口调用成功');
          }
        }
    }
</script>
<style>
    .calendar-day{
        text-align: center;
        color: #202535;
        line-height: 30px;
        font-size: 12px;
    }
    .is-selected{
        color: #F8A535;
        font-size: 10px;
        margin-top: 5px;
    }
    #calendar .el-button-group>.el-button:not(:first-child):not(:last-child):after{
        content: '当月';
    }
</style>
  • 14
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

接口写好了吗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值