javascript - Vue Full Calendar (next, prev) 按钮触发

标签 javascript vue.js vuejs2 fullcalendar

我正在使用 https://www.npmjs.com/package/vue-full-calendar在项目中。我遇到了

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

我的后端 api 建立在参数月份返回事件上。我在 Vuejs 中有请求方法,它接受参数并返回事件。对于当前月份,我只是在 created() 函数中使用 fetch 方法,它返回事件,我只是简单地使日历事件等于:

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

现在我需要了解用户何时单击下一个或上一个按钮以触发具有属性月份和重新获取事件的此请求。我没有找到制作它的方法,唯一的方法是使用 jQuery。

最佳答案

您可以覆盖默认按钮:

<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>

关于javascript - Vue Full Calendar (next, prev) 按钮触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50887335/

相关文章:

JavaScript 连接应该计数的数字

javascript - 选择日期后如何删除 html 5 中的 X 标记(清除按钮)[输入类型 ="date"]

javascript - 如何直接显示input的值

javascript - 如何从循环中返回值。 js、vuejs

vue.js - Vuetify 深色主题定制不起作用

javascript - 使用 Jest 测试组件时如何定位选择器的第一个子级

javascript - react + Redux : Invariant Violation: Could not find "store" in either the context or props of "Connect(Body)"

node.js - 为什么对 Babel 和 ESLint 使用 Vue CLI?

javascript - 检测VUE中是否点击刷新按钮

javascript - Vue 变量在 Vuex 中无法访问