首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Vue.js中删除FullCalendar-4事件

如何在Vue.js中删除FullCalendar-4事件
EN

Stack Overflow用户
提问于 2019-07-20 14:07:49
回答 1查看 842关注 0票数 0

我正在尝试使用FullCalendarV4Vue.js构建一个交互式日历。到目前为止,我已经将代码设置为在handleDateClick函数中使用prompt方法启用事件输入。我想附加一个功能删除按钮到每个事件。文档中说这可以使用eventRender回调来完成。我试着使用这个回调来追加一个按钮,但是没有用。对如何实现这一点有什么建议吗?我的代码如下。谢谢!

代码语言:javascript
复制
<template>
  <div class='demo-app'>
    <FullCalendar
      class='demo-app-calendar'
      ref="fullCalendar"
      defaultView="dayGridMonth"
      :header="{
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
       }"
      :plugins="calendarPlugins"
      :weekends="calendarWeekends"
      :events="calendarEvents"
      @dateClick="handleDateClick"
      />
  </div>
</template>

<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'

export default {
  components: {
    FullCalendar // make the <FullCalendar> tag available
  },
  data: function() {
    return {
      calendarPlugins: [ // plugins must be defined in the JS
        dayGridPlugin,
        timeGridPlugin,
        interactionPlugin // needed for dateClick
      ],
      calendarWeekends: true,
      calendarEvents: []
    }
  },
  methods: {
    handleDateClick(arg) {
    var newTitle = prompt(arg.dateStr);
      if (newTitle != null) {
        this.calendarEvents.push({
          title: newTitle,
          start: arg.date,
          allDay: arg.allDay
        })
      }
    },
    eventRender: function(event){
      var btn = document.createElement("button");
      btn.appendChild(document.createTextNode("x"));
      event.appendChild(btn);
    }
  }
}
</script>

<style lang='scss'>

// 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;
}

</style>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-20 18:50:25

要访问eventRender中的元素,需要将@eventRender方法绑定到FullCalendar组件上,需要使用event.el。你可以查看the document here

代码语言:javascript
复制
   <FullCalendar
          class='demo-app-calendar'
          ref="fullCalendar"
          defaultView="dayGridMonth"
          :header="{
            left: 'prev,next today',
            center: 'title',
            right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
          }"
          :plugins="calendarPlugins"
          :weekends="calendarWeekends"
          :events="calendarEvents"
          @dateClick="handleDateClick"
          @eventRender="eventRender"
    />

    methods: {
        eventRender(info) {
          var btn = document.createElement("button");
          btn.appendChild(document.createTextNode("x"));
          info.el.appendChild(btn);
        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57122239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档