代码之家  ›  专栏  ›  技术社区  ›  Roster

无法在React js web应用程序中使用材质ui选取器

  •  0
  • Roster  · 技术社区  · 7 年前

    我正在尝试在react应用程序中实现materialui picker。

    从下面的代码集成 link

    enter image description here

    我在单独的文件中使用了文档中的代码,并安装了所有的软件包,但是没有找到获取模块:错误:无法解析'date fns/format' 然后我尝试从node modules文件夹路径导入datefns链接,如下所示 然后低于错误。 enter image description here

    是否有人成功地集成了材质ui选取器。。 请提出建议

    0 回复  |  直到 6 年前
        1
  •  12
  •   Dmitriy Kovalenko    6 年前

    official documentation

    您需要安装并传递utils。首先为库安装实用程序:

    npm install date-fns @date-io/date-fns
    

    然后将它们传递给utils提供者

    import React, { useState } from "react";
    import DateFnsUtils from "@date-io/date-fns"; // import
    import { DatePicker, MuiPickersUtilsProvider } from "@material-ui/pickers";
    
    function App() {
      const [selectedDate, handleDateChange] = useState(new Date());
    
      return (
        <MuiPickersUtilsProvider utils={DateFnsUtils}>
          <DatePicker value={selectedDate} onChange={handleDateChange} />
        </MuiPickersUtilsProvider>
      );
    }
    

    Here 是沙盒游戏:)

        2
  •  1
  •   Andreas_Lng    6 年前

    npm i @date-io/date-fns@1.x date-fns
    

    npm i @date-io/moment@1.x moment
    

    npm i -s @date-io/luxon@1.x luxon
    

    npm i -s @date-io/dayjs@1.x dayjs
    

    (“的 @date-io 图书馆发布了一个新的版本v2,打破了这个模块。

    同时。”)