如何为 react-big-calendar (fullcalendar.js) 设置 momentLocalizer (moment.js)? [英] How to set momentLocalizer (moment.js) for react-big-calendar (fullcalendar.js)?

查看:82
本文介绍了如何为 react-big-calendar (fullcalendar.js) 设置 momentLocalizer (moment.js)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-big-calendar并且需要帮助来实施所需的本地化来自git的例子

从'react-big-calendar'导入BigCalendar;从时刻"导入时刻;BigCalendar.setLocalizer(BigCalendar.momentLocalizer(时刻));

我的代码

var moment = require('moment');var momentLocalizer = require('react-widgets/lib/localizers/moment');从 'react-big-calendar' 导入 BigCalendar;BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment.locale('en')));让我的日历 = 道具 =>(<div><大日历/>

);

我试过的都行不通

<块引用>

未捕获的类型错误:moment 不是函数

解决方案

下面是我的代码,对我有用.如果我想更改本地化,我只需在 BigCalendar 上设置 culture 道具.

import React, { Component } from 'react';导入 'react-big-calendar/lib/css/react-big-calendar.css'从 'react-big-calendar' 导入 BigCalendar;从时刻"导入时刻;BigCalendar.momentLocalizer(时刻);类日历扩展组件{构造函数(道具,上下文){超级(道具,上下文);}使成为() {返回 (<div><大日历文化='zh-GB'事件={this.props.tasks}视图={['月', '周']}/>

);}}

I'm using react-big-calendar And need help to implement localization which is required The example from git

import BigCalendar from 'react-big-calendar';
import moment from 'moment';

BigCalendar.setLocalizer(
  BigCalendar.momentLocalizer(moment)
);

My code

var moment = require('moment');
var momentLocalizer = require('react-widgets/lib/localizers/moment');
import BigCalendar from 'react-big-calendar';

BigCalendar.setLocalizer(
    BigCalendar.momentLocalizer(moment.locale('en'))
);

let MyCalendar = props => (
    <div>
        <BigCalendar

        />
    </div>
);

Whatever I tried it doesn't work

Uncaught TypeError: moment is not a function

解决方案

My code below, it works for me. I simply set the culture prop on my BigCalendar if I want to change localization.

import React, { Component } from 'react';
import 'react-big-calendar/lib/css/react-big-calendar.css'
import BigCalendar from 'react-big-calendar';
import moment from 'moment';

BigCalendar.momentLocalizer(moment);

class Calendar extends Component {
    constructor(props, context) {
      super(props, context);
    }

    render() {
      return (
        <div>
          <BigCalendar
            culture='en-GB'
            events={this.props.tasks}
            views={['month', 'week']}/>
        </div>
      );
    }
  }

这篇关于如何为 react-big-calendar (fullcalendar.js) 设置 momentLocalizer (moment.js)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆