vue vant Calendar日历定制

2 篇文章 0 订阅
该代码示例展示了如何在Vue.js应用中使用Vant的Calendar组件来创建一个可定制的日历,包括设置最小和最大日期,显示月份切换按钮,以及处理日期范围。日历标题可自定义,并隐藏了默认标记、副标题和确认按钮。
摘要由CSDN通过智能技术生成

calendar文档

<template>
...
     <Calendar :min-date="start" :max-date="end"
               :title="null" :show-mark="false" :show-subtitle="false" :show-confirm="false" :show-title="true"
               :poppable="false" :round="false"  >
       <template v-slot:title>
         <div style="background-color: red;height: 100%;display: flex;align-items: center;justify-content: center;">
           <span @click="preMonth" style="margin-right: 10px">上一月</span>
           {{dateStr}}
           <span @click="NextMonth" style="margin-left: 10px">下一月</span>
         </div>
       </template>
     </Calendar>
...
</template>
<script>
 import { Calendar } from 'vant';
  export default {
	components: {
	  Calendar
	},
	data(){
	   return{
	      ...
	      dateStr:new Date().getFullYear()+"-"+(new Date().getMonth()+1),
          start:new Date(new Date().getFullYear(), new Date().getMonth(),1),
          end:new Date(new Date().getFullYear(), new Date().getMonth(),31),
          ...
       }
	},
	methods:{
	  ...
      NextMonth(){
        console.log("NextMonth")
        // start:new Date(new Date().getFullYear(), new Date().getMonth(),1),
        //   end:new Date(new Date().getFullYear(), new Date().getMonth(),31),
        let start =  this.start
        let end =  this.end
        this.start = new Date(start.getFullYear(), start.getMonth()+1,1)
        this.end = new Date(end.getFullYear(), end.getMonth()+1,new Date(start.getFullYear(), start.getMonth()+1,0).getDate())
        this.dateStr = this.start.getFullYear()+"-"+(this.start.getMonth()+1)
      },
      preMonth(){
        console.log("preMonth")
        let start =  this.start
        let end =  this.end
        this.start = new Date(start.getFullYear(), start.getMonth()-1,1)
        this.end = new Date(end.getFullYear(), end.getMonth()-1,new Date(start.getFullYear(), start.getMonth()-1,0).getDate())
        this.dateStr = this.start.getFullYear()+"-"+(this.start.getMonth()+1)
      },
    }
 }
</script>

<style lang="less" scoped>
...
/deep/.van-calendar__month-title{
  display: none;
}
</style>

效果如图:在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值