我已经为我的项目下载了一个开源日历,但出现此导入错误。
./ src / DemoApp.js 找不到模块:无法解析'/ Users / johanozbek / Desktop / Calendar / calendar / src'中的'@ fullcalendar / interaction'<< / p>
这是我想在我的项目中拥有的开源项目。 https://github.com/fullcalendar/fullcalendar-example-projects/tree/master/react
import React from 'react'
import FullCalendar from '@fullcalendar/react'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction' // needed for dayClick
import './main.scss'
export default class DemoApp extends React.Component {
calendarComponentRef = React.createRef()
state = {
calendarWeekends: true,
calendarEvents: [ // initial event data
{ title: 'Event Now', start: new Date() }
]
}
render() {
return (
<div className='demo-app'>
<div className='demo-app-top'>
<button onClick={this.toggleWeekends}>toggle weekends</button>
<button onClick={this.gotoPast}>go to a date in the past</button>
(also, click a date/time to add an event)
</div>
<div className='demo-app-calendar'>
<FullCalendar
defaultView="dayGridMonth"
header={{
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
}}
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
ref={this.calendarComponentRef}
weekends={this.state.calendarWeekends}
events={this.state.calendarEvents}
dateClick={this.handleDateClick}
/>
</div>
</div>
)
}
toggleWeekends = () => {
this.setState({ // update a property
calendarWeekends: !this.state.calendarWeekends
})
}
gotoPast = () => {
let calendarApi = this.calendarComponentRef.current.getApi()
calendarApi.gotoDate('2000-01-01') // call a method on the Calendar object
}
handleDateClick = (arg) => {
if (window.confirm('Would you like to add an event to ' + arg.dateStr + ' ?')) {
this.setState({ // add new event data
calendarEvents: this.state.calendarEvents.concat({ // creates a new array
title: 'New Event',
start: arg.date,
allDay: arg.allDay
})
})
}
}
}
// you must include each plugins' css
// paths prefixed with ~ signify node_modules
@import '~@fullcalendar/core/main.css';
@import '~@fullcalendar/daygrid/main.css';
@import '~@fullcalendar/timegrid/main.css';
.demo-app {
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
.demo-app-top {
margin: 0 0 3em;
}
.demo-app-calendar {
margin: 0 auto;
max-width: 900px;
}