微信小程序日历组件

文章目录

    在小程序里做打卡记录功能时,发现了一个不错的日历组件:

    https://github.com/treadpit/wx_calendar

    虽然很好用,效果也不错。但是文档有点简单,好多细节没有覆盖到。这里记录一下。

    cannot read property ‘setDateStyle’ of undefined

    偶发性错误。大概三分之一的概率会出现。

    在小程序页面 onShow 里的 http 回调中,执行

    this.calendar.setDateStyle(toSet);
    

    报错。

    cannot read property ‘setDateStyle’ of undefined

    问题原因,在 github issue 中找到了。

    this.calendar 上的方法需要在 afterCalendarRender 后,在页面 onLoad 或 初次触发 onShow 的时候,日历可能还未渲染完成,所以此时调用日历方法会提示为 undefined。

    设置有数据日期样式的坑

    有内层,外层之分。需要注意一下。