`$(..).fullCalendar 不是 React 中的一个函数



所以我读了大约 15 篇有类似问题的不同帖子,但它们似乎都是由不正确加载 jQuery 或不正确加载全日历引起的。但是,我知道我正在将两者加载到我的组件中(我不确定我是否正确执行(。我在我的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>
        );
    }
}

我从console.log(fc)得到的输出是:

Object {version: "3.4.0", internalApiVersion: 9, views: Object, intersectRanges: function, applyAll: function…}
AgendaView:function ()
BasicView:function ()
Calendar:function (el, overrides)
Class:function Class()
CoordCache:function (options)
DayGrid:function ()
DayTableMixin:Object
DragListener:function (options)
EmitterMixin:Object
Grid:function (view)
ListenerMixin:Object
Model:function ()
MonthView:function ()
Promise:Object
RenderQueue:function (waitsByNamespace)
Scroller:function (options)
TaskQueue:function ()
TimeGrid:function ()
View:function (calendar, viewSpec)
applyAll:function applyAll(functions, thisObj, args)
capitaliseFirstLetter:function capitaliseFirstLetter(str)
compareByFieldSpec:function compareByFieldSpec(obj1, obj2, fieldSpec)
compareByFieldSpecs:function compareByFieldSpecs(obj1, obj2, fieldSpecs)
computeGreatestUnit:function computeGreatestUnit(start, end)
createObject:function createObject(proto)
cssToStr:function cssToStr(cssProps)
dataAttrPrefix:""
datepickerLocale:function (localeCode, dpLocaleCode, dpOptions)
debounce:function debounce(func, wait, immediate)
divideDurationByDuration:function divideDurationByDuration(dur1, dur2)
divideRangeByDuration:function divideRangeByDuration(start, end, dur)
durationHasTime:function durationHasTime(dur)
flexibleCompare:function flexibleCompare(a, b)
formatDate:function formatDate(date, formatStr)
formatRange:function formatRange(date1, date2, formatStr, separator, isRTL)
getClientRect:function getClientRect(el, origin)
getContentRect:function getContentRect(el, origin)
getOuterRect:function getOuterRect(el, origin)
getScrollbarWidths:function getScrollbarWidths(el)
htmlEscape:function htmlEscape(s)
internalApiVersion:9
intersectRanges:function intersectRanges(subjectRange, constraintRange)
intersectRects:function intersectRects(rect1, rect2)
isBgEvent:function isBgEvent(event)
isInt:function isInt(n)
locale:function (localeCode, newFcOptions)
locales:Object
log:function ()
moment:function ()
multiplyDuration:function multiplyDuration(dur, n)
oldMomentFormat:function oldMomentFormat(mom, formatStr)
parseFieldSpecs:function parseFieldSpecs(input)
pluckEventDateProps:function pluckEventDateProps(event)
preventDefault:function preventDefault(ev)
proxy:function proxy(obj, methodName)
queryMostGranularFormatUnit:function queryMostGranularFormatUnit(formatStr)
sourceFetchers:Array(0)
sourceNormalizers:Array(0)
touchMouseIgnoreWait:500
version:"3.4.0"
views:Object
warn:function ()
__proto__:Object

所以我很确定这是对的。

我从console.log($('#calendar'))那里得到的是:

[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"
})

我不明白,但 https://github.com/angular-ui/ui-calendar/issues/349#issuecomment-250865512 进一步阅读。

我认为这与webpack配置有关。

您应该:

  • 将 jQuery 和 fullCalendar 声明为外部并全局添加它们
  • 使用此配置 https://github.com/angular-ui/ui-calendar/issues/349#issuecomment-250865512

相关内容

  • 没有找到相关文章

最新更新