材质UI日期时间选择器示例 [英] Material UI Date Time Picker example

查看:114
本文介绍了材质UI日期时间选择器示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解材料UI日期时间选择器.

问题是在Codesandbox上给定的示例导致错误,因为以下导入无法找到:

The problem is that the given example on Codesandbox leads to errors, because the following import cannot be found:

import DateFnsUtils from '@date-io/date-fns';

我已经尝试在几次测试中消除该错误,但均未成功.我的猜测是它从 npm 导入了一个损坏的版本.因此,我相信它必须是 package.json 中的以下软件包之一:

I already have tried unsuccessfully to get rid of that error in several tests. My guess is that it imports a corrupt version from npm. Hence, I believe it must be one of the following packages within the package.json:

"date-fns": "next",
"@types/date-ioDate-fns": "latest",
"@types/date-fns": "latest",
"@date-io/date-fns": "latest"

有没有一种方法可以不使用 date-fns 来启动并运行该示例?

Is there a way not to use date-fns in order to get the example up and running?

推荐答案

只需将 tslib 添加到依赖项列表中,就像 @ date-io/date-fns 那样同行对此未满足的依赖.

Just add tslib to your list of dependencies, as @date-io/date-fns has an unmet peer dependency on it.

https://codesandbox.io/s/material-demo-hrz3c?fontsize = 14&hidenavigation = 1& theme = dark

值得注意的是,虽然这修复了依赖性,但您可能会收到以下错误:

格式字符串包含未转义的拉丁字母字符"n"

Format string contains an unescaped latin alphabet character `n`

可悲的是,这是 date-fns 库2.x版本的错误,至少根据

Sadly this is fault of date-fnslibrary 2.x release and at least according to this issue your best bet is to downgrade to 1.3.13

我可以确认,降级至1.3.13至少可以解决我的沙箱中的问题

这篇关于材质UI日期时间选择器示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆