最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue FullCalendar, setting click event - Stack Overflow

programmeradmin2浏览0评论

I'm using the FullCalendar library for Vue and I have a perfectly working calendar, but I can't get clicking on date/calendar events to work.

I have the calendar in the template:

<full-calendar @dateClick="handleDateClick" :config="config" :events="events"/></full-calendar>

and my vue code:

export default {
    data () {
        return {
            events: [
              title: 'My Event',
              start: '2010-01-01'
            ],
            config: {
                defaultView: 'month',
                editable:true,
                eventRender: function(event, element) {
                    console.log(event)
                }
            },
        }
    },
    methods: {
      handleDateClick(arg) {
        alert(arg.date)
      },
    },
}

This seems to match the docs but I'm not getting the alert. I'm just trying to make it so that I have the functionality in place so that I can tie each event click to a modal with that event's details.

What exactly am I doing wrong here?

I'm using the FullCalendar library for Vue https://fullcalendar.io/docs/vue and I have a perfectly working calendar, but I can't get clicking on date/calendar events to work.

I have the calendar in the template:

<full-calendar @dateClick="handleDateClick" :config="config" :events="events"/></full-calendar>

and my vue code:

export default {
    data () {
        return {
            events: [
              title: 'My Event',
              start: '2010-01-01'
            ],
            config: {
                defaultView: 'month',
                editable:true,
                eventRender: function(event, element) {
                    console.log(event)
                }
            },
        }
    },
    methods: {
      handleDateClick(arg) {
        alert(arg.date)
      },
    },
}

This seems to match the docs but I'm not getting the alert. I'm just trying to make it so that I have the functionality in place so that I can tie each event click to a modal with that event's details.

What exactly am I doing wrong here?

Share Improve this question asked Sep 9, 2019 at 11:59 Geoff_SGeoff_S 5,1057 gold badges58 silver badges168 bronze badges 2
  • any errors in your console? – ADyson Commented Sep 9, 2019 at 14:44
  • No errors at all, that's one thing that doesn't make sense – Geoff_S Commented Sep 9, 2019 at 14:54
Add a ment  | 

2 Answers 2

Reset to default 4

You need to add selectable:true as the default is false. And you need the interactionPlugin as well.

https://fullcalendar.io/docs/selectable https://fullcalendar.io/docs/plugin-index

import interactionPlugin from '@fullcalendar/interaction'
config:{
...
selectable:true,
plugins:[interactionPlugin]
}

I have the following setup and it allows me to click and click and drag. Your code is only missing @select="".

<template>
  <FullCalendar 
    defaultView="dayGridMonth" 
    :plugins="calendarPlugins" 
    :events="events"
    :selectable="true"
    @select="handleSelect"
    @clickDate="handleDateClick"
  />
</template>


<script>
/* eslint-disable */
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction';


export default {
  name: 'Home',
  ponents: {
    FullCalendar
  },
  mounted(){

  },
  data () {
    return {
      events: [{title:'Something', start:'2019-09-12'}],
      calendarPlugins:[dayGridPlugin, interactionPlugin]
    }
  },
  methods:{
    handleDateClick(e){
      console.log(e);
    },
    handleSelect(e){
      console.log(e);
    }
  }
}
</script>

<style lang='scss'>

  @import '~@fullcalendar/core/main.css';
  @import '~@fullcalendar/daygrid/main.css';
  @import '~@fullcalendar/timegrid/main.css';
  @import '~@fullcalendar/list/main.css';

</style>
发布评论

评论列表(0)

  1. 暂无评论