【Vant 日历】-实现平铺自定义日历内容

【Vant 日历】

前提:引入Vant组件

步骤一,json中定义
"usingComponents": {
    "van-calendar": "@vant/weapp/calendar/index"
 },
步骤二,页面中使用
<view class="popcalender">
  <van-calendar
  poppable="{{ false }}" //是否以弹层的形式展示日历
  show-title="{{false}}" //	是否展示日历标题
  show-mark="{{false}}" //是否显示月份背景水印
  formatter="{{ formatter }}" //自定义日期文案,通过传入formatter函数来对日历上每一格的内容进行格式化
  confirm-text="完成"//确认按钮的文字
  default-date="" //默认选中的日期,默认今天
  show-subtitle="{{false}}" //是否展示日历副标题(年月)
  show-confirm="{{ false }}" //是否展示确认按钮
  class="calendar"
/>
</view>

步骤三:重点,如何自定义日期文案

//onLoad中
 onLoad: function (options) {
    this.cander()
  },
//方法
 cander() {
    this.setData({
      formatter: function (day) {
        // 业务代码
        const month = day.date.getMonth() + 1;
        const date = day.date.getDate();
        if (month === 5) {
          if (date === 1) {
            day.topInfo = '上方文字';
            day.bottomInfo="下方文字"
            day.text="中间文字"
            day.className="类名"
          } else if (date === 4) {
            day.topInfo = '五四青年节';
          } else if (date === 11) {
            day.text = '今天';
          }
        }
        //自定义日期间隔的开始和结束文案和样式
        if (day.type === 'start') {
          day.bottomInfo = '入住';
        } else if (day.type === 'end') {
          day.bottomInfo = '离店';
        }
        return day;
      }
    })
  },

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值