likes
comments
collection
share

antd:TypeError: clone.weekday is not a function

作者站长头像
站长
· 阅读数 22

在antd组件库日期时间组件中自带的moment(5换为了dayjs),因为dayjs是插件化的形式,为了保证包的体积,很多函数需要额外注册,我猜测应该是选择器用到了某一个函数但是没有被dayjs注册的原因。在dayjs全局中注册一下就行了,可以在全局环境中添加这段代码,也可以在使用选择器的页面添加,也可以对dayjs进行额外封装。

我的解决:

import weekday from "dayjs/plugin/weekday";
import localeData from "dayjs/plugin/localeData";
dayjs.extend(weekday);
dayjs.extend(localeData);

antd:TypeError: clone.weekday is not a function

我看到有的教程引入了多个插件,可以进行参考。

参考代码:

import dayjs from 'dayjs'
import advancedFormat from 'dayjs/plugin/advancedFormat'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import localeData from 'dayjs/plugin/localeData'
import weekday from 'dayjs/plugin/weekday'
import weekOfYear from 'dayjs/plugin/weekOfYear'
import weekYear from 'dayjs/plugin/weekYear'

dayjs.extend(customParseFormat)
dayjs.extend(advancedFormat)
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)

参考链接:

antd:TypeError: clone.weekday is not a function

https://stackoverflow.com/questions/76650410/antd-dayjs-typeerror-clone-weekday-is-not-a-function

https://github.com/react-component/picker/issues/123