Vue Full Calendar (next, prev) buttons trigger

原文:https://stackoverflow.com/questions/50887335/vue-full-calendar-next-prev-buttons-trigger

Asked 1 year, 11 months ago
Active 1 month ago
Viewed 2k times
1

I'm using https://www.npmjs.com/package/vue-full-calendar in the project. I run into

problem when I need to get callback or trigger of next and prev buttons of calendar.

My api of backend built on parameter month returing events. I have request methods in Vuejs, which accept parameter and return events. For current month I just use the fetch method in created() function, it returns events and I simply make equals to calendar events, something like that:

axios.get(/fetch/events?month=6).then(e => this.events = this.responseToEvents(e.data)).catch( e => ...).

Now I need to understand when user click on next or previous buttons for triggering this request with property month and refetch events. I didn't find a way to make it, the only way is to use jQuery.

  •  
    Your plugin is just a wrapper around fullcalender, which is a jQuery plugin. Every jQuery event is emitted through the plugin. You can just use on of these callbacks described in the doku fullcalendar.io/docs/event-display – Reiner Jun 16 '18 at 19:19

3 Answers

1

Create a button yourself and give it a @click="next" event https://github.com/CroudTech/vue-fullcalendar#methods

0

Emitted Events: changeMonth
e.g.

<template>
  <full-calendar
    @changeMonth="changeMonth"
  ></full-calendar>
</template>

import FullCalendar from 'vue-fullcalendar'

...
  components: {
    FullCalendar
  },
...

methods: {
  changeMonth(start, end, currentMonthStartDate) {
     console.log(currentMonthStartDate); // the start date of the current month after changing month by clicking the '<'(previous) or '>'(next) button
  }
}
0

You can override default buttons:

<full-calendar ref="fullCalendar" :custom-buttons="customButtons" :header="header" />
<script>   
  data() {
    return {
      header: {
        left: "prev,next today",
        center: "title",
        right: "dayGridMonth,timeGridWeek,timeGridDay,listWeek"
      },
      customButtons: { 
        prev: { // this overrides the prev button
          text: "PREV", 
          click: () => {           
            console.log("eventPrev");
            let calendarApi = this.$refs.fullCalendar.getApi();
            calendarApi.prev();
          }
        },
        next: { // this overrides the next button
          text: "PREV",
          click: () => {
             console.log("eventNext");
             let calendarApi = this.$refs.fullCalendar.getApi();
             calendarApi.next();
          }
        }
      }
    }

</script>

posted @ 2020-05-15 14:38  鳳舞九天  阅读(1581)  评论(0编辑  收藏  举报