【问题标题】:How to import moment-precise-range-plugin in React.js?如何在 React.js 中导入 moment-precise-range-plugin?
【发布时间】:2022-01-13 02:21:53
【问题描述】:

我正在尝试使用 moment-precise-range-plugin 来查找两个日期之间的差异。所以,我尝试在 React 中导入这样的包

import moment from "moment";
import "moment-precise-range";

然后,我尝试在我的代码中使用它

console.log(moment.preciseDiff(endDate, startDate, true));

我收到此错误 未捕获的类型错误:moment__WEBPACK_IMPORTED_MODULE_0___default(...).preciseDiff 不是函数

我绝对理解问题仅在于导入。如何正确导入?

参考资料:

moment-precise-range-plugin npm

Moment.js precise-range plugin

【问题讨论】:

    标签: reactjs npm import momentjs


    【解决方案1】:

    来自文档:
    要在 node.js 应用程序中使用该插件,请将以下 require 语句添加到您的代码中:

    require('moment-precise-range-plugin');
    

    或者:

    import 'moment-precise-range-plugin';
    

    这里的问题是您在导入语句中缺少字符串“-plugin”...

    【讨论】:

      猜你喜欢
      • 2015-08-17
      • 2022-01-18
      • 2017-01-20
      • 2021-10-05
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 2020-04-04
      相关资源
      最近更新 更多