繁体   English   中英

“无法读取未定义事件的属性”Vue.JS

[英]'Cannot read properties of undefined events' Vue.JS

  <FullCalendar id="calendar"
  :options="calendarOptions"
  />
</section>

export default {
  components: {
    FullCalendar
  },
  
  
  data() {
    return {
      calendarOptions: {
        plugins: [dayGridPlugin ,interactionPlugin, timeGridPlugin, listPlugin],

  methods:{
    newEvent(){
      var theCalendar = document.getElementById("calendar");
      var eventName = document.getElementById("Ename").value;
      var sDate = document.getElementById("startDate").value;
      var eDate = document.getElementById("endDate").value;
      var type = document.getElementById("bookingType").value;
      var number = document.getElementById("numberOfPeople").value;
      
      //The addEvent can't be accessed, currently this function doesn't have access to the object Fullcalendar and because of that
      //we can't use addEvent.
        theCalendar.addEvent({
        title: eventName,
        start: sDate,
        allDay: true
      });
      alert('Great. Now, update your database...');

    }
  }

您好,我的 vue.JS 代码目前无法读取未定义的属性。 我希望能够使用我的日历属性填充 addEvent 类。

如果您尝试访问 API

你应该在你的日历上提供一个参考

<FullCalendar ref="fullCalendar" :options="calendarOptions" />

然后可以这样访问

let calendarApi = this.$refs.fullCalendar.getApi()
calendarApi.next()

这里

但是我怀疑您实际上想要的是访问 calendarOptions 对象,它很简单

this.calendarOptions.events

假设您已按照上一个链接中的指定定义对象

data() {
  return {
    calendarOptions: {
      plugins: [ dayGridPlugin, interactionPlugin ],
      events: [
        { title: 'event 1', date: '2019-04-01' },
        { title: 'event 2', date: '2019-04-02' }
      ]
    }
  }
},

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM