为什么我的 React 组件无法获取我需要的库

Why is my React component unable to pick up the library I am requiring?

本文关键字:获取 我的 React 组件 为什么      更新时间:2023-09-26

我正在尝试在我的 React 项目中使用 FullCalendar.io。

我已经使用 npm install fullcalendar 安装了它。

我在目录中看到node_modules/fullcalendar

在我的项目中,我正在使用:

var Scheduler = require('fullcalendar');

然后我有:

var Calendar = React.createClass({
    componentDidMount: function () {
        $('#calendar').fullCalendar();
    },
    render: function () {
        return (
            <div id='calendar'>
            </div>
        );
    }
});

然而,我收到此错误:Uncaught TypeError: $(...).fullCalendar is not a function

(旁注 - 需要其他模块可以正常工作。我可以做var moment = require('moment')然后做一个console.log(moment()),它会输出一个新的矩变量。

确保需要每个组件中启动的所有库。仅将其放在需要转换/捆绑的文件的索引文件中是行不通的。(需要在 React 应用程序中使用 jQuery 有点可悲,因为 jQuery 是为了克服不知道你的元素在哪里/是什么的问题,而在 React 中你总是知道你的元素是什么)