Javascript `$(…)。fullCalendar不是React中的函数

Javascript `$(…)。fullCalendar不是React中的函数,javascript,jquery,reactjs,fullcalendar,components,Javascript,Jquery,Reactjs,Fullcalendar,Components,所以我读过15篇有类似问题的帖子,但它们似乎都是由jQuery加载不当或fullcalendar加载不当引起的。但是,我知道我正在将这两个组件都加载到我的组件中(我不确定是否正确地进行了加载)。我在package.json中使用fullcalendarnpm 我的组成部分: import React from 'react'; import moment from 'moment'; import fc from 'fullcalendar'; export default class Dai

所以我读过15篇有类似问题的帖子,但它们似乎都是由jQuery加载不当或fullcalendar加载不当引起的。但是,我知道我正在将这两个组件都加载到我的组件中(我不确定是否正确地进行了加载)。我在
package.json
中使用
fullcalendar
npm

我的组成部分:

import React from 'react';
import moment from 'moment';
import fc from 'fullcalendar';

export default class DailyEvents extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
        }
    }

    componentDidMount() {
        console.log(fc)
        console.log($('#calendar'))
        $('#calendar').fullCalendar();
    }

    render () {
        return (
            <div id="calendar"></div>
        );
    }
}
所以我很确定这是对的

我从控制台.log($(“#日历”)中得到的是:

[div#calendar, context: document, selector: "#calendar"]
0:div#calendar
context:document
length:1
selector:"#calendar"
__proto__:Object(0)
我也觉得不错

我不知道我哪里出错了

编辑:

解决方案是将以下内容添加到
webpack.config.js
中的插件中:

new webpack.ProvidePlugin({
    $: "jquery",
    "window.jQuery": "jquery",
    "moment": "moment"
})

我不明白,但需要进一步阅读。

我认为这与网页配置有关

你应该:

  • 将jQuery和fullCalendar声明为外部并全局添加它们
  • 使用此配置

更好地使用
refs
?最初使用参考文献。同样的结果。我把它改为id,以确保我没有把jquery搞砸,因为引用会试图解决查找元素的问题,对吗?但是我很明显找到了我的控制台输出所指示的元素,我不太确定,但这可能是一个网页问题。这是我找到的另一个帖子
new webpack.ProvidePlugin({
    $: "jquery",
    "window.jQuery": "jquery",
    "moment": "moment"
})