admin管理员组文章数量:1389762
Inside of my cal.vue ponent I have a fullcalendar
ponent. Within cal.vue I have a method called submit. Inside of submit I make a (successful) reference to the fullcalendar
ponent with this.$refs.calendar
. However when I do this.$refs.calendar.$emit('refetchEvents');
in my submit function the events are not fetched (my events are not updated on my calendar). Why are my events not being updated upon submit and how can I update them?
Here is the relevant code:
<template>
<div id="calendar" :navL="navLinks" :event-sources="eventSources" @event-selected="eventSelected" @event-created="eventCreated" :config="config" >
<button class="btn btn-secondary" v-on:click="submit()">
Submit
</button>
<full-calendar id="target" ref="calendar" :event-sources="eventSources" @event-selected="eventSelected" @day-click="click"@event-created="eventCreated" :config="config"></full-calendar>
</div>
</template>
<script>
const self = this;
export default {
name: 'calendar',
data() {
return {
eventSources: [
{
url: 'http://localhost:3000/getAppointments',
type: 'GET',
data: {
id: this.$store.getters.user
},
error: function() {
alert('there was an error while fetching events!');
},
}
],
};
},
methods: {
submit: function() {
console.log(this.$refs.calendar); //prints fullcalendar VUE ponent
this.$refs.calendar.$emit('refetchEvents'); //nothing appears to happen here
},
},
}
</script>
Inside of my cal.vue ponent I have a fullcalendar
ponent. Within cal.vue I have a method called submit. Inside of submit I make a (successful) reference to the fullcalendar
ponent with this.$refs.calendar
. However when I do this.$refs.calendar.$emit('refetchEvents');
in my submit function the events are not fetched (my events are not updated on my calendar). Why are my events not being updated upon submit and how can I update them?
Here is the relevant code:
<template>
<div id="calendar" :navL="navLinks" :event-sources="eventSources" @event-selected="eventSelected" @event-created="eventCreated" :config="config" >
<button class="btn btn-secondary" v-on:click="submit()">
Submit
</button>
<full-calendar id="target" ref="calendar" :event-sources="eventSources" @event-selected="eventSelected" @day-click="click"@event-created="eventCreated" :config="config"></full-calendar>
</div>
</template>
<script>
const self = this;
export default {
name: 'calendar',
data() {
return {
eventSources: [
{
url: 'http://localhost:3000/getAppointments',
type: 'GET',
data: {
id: this.$store.getters.user
},
error: function() {
alert('there was an error while fetching events!');
},
}
],
};
},
methods: {
submit: function() {
console.log(this.$refs.calendar); //prints fullcalendar VUE ponent
this.$refs.calendar.$emit('refetchEvents'); //nothing appears to happen here
},
},
}
</script>
Share
Improve this question
edited Jul 14, 2017 at 2:46
Bert
82.5k17 gold badges203 silver badges166 bronze badges
asked Jul 13, 2017 at 14:06
MattMatt
5014 silver badges14 bronze badges
6
-
What is
full-calendar
? A Vue ponent wrapping a jQuery plugin? Does it still use jQuery? – Bert Commented Jul 13, 2017 at 16:24 - full-calendar is a VUE ponent wrapping the jQuery plugin fullcalendar. I believe it uses jQuery – Matt Commented Jul 13, 2017 at 17:26
- Do you have a link? There are at least two Vue wrappers. – Bert Commented Jul 13, 2017 at 17:27
- calendar.vue is where the above code is located – Matt Commented Jul 13, 2017 at 17:40
- If the VUE code looks ok it could be a problem with the vue-fullcalendar wrapper I am using. I'll post an issue to them and see what they say – Matt Commented Jul 13, 2017 at 17:57
2 Answers
Reset to default 4According to the documentation,
this.$refs.calendar.$emit('refetchEvents')
should be
this.$refs.calendar.$emit('refetch-events')
If using the vanilla FullCalendar via npm packages: "@fullcalendar/core", "@fullcalendar/daygrid", "@fullcalendar/timegrid", "@fullcalendar/vue"
html: <full-calendar ref="fullCalendar" :events="events" />
inside a method to update an event:
let calendar = this.$refs.fullCalendar.getApi()
const updatedEvent = calendar.getEventById(eventId)
updatedEvent.setProp('title', 'New Title')
updatedEvent.setProp('backgroundColor', 'yellow')
updatedEvent.setProp('borderColor', 'yellow')
updatedEvent.setProp('textColor', 'black')
The above will rerender the fullCalendar event but will not change your this.events array. There may be something that's a bit more all inclusive for ALL events in one shot otherwise you'd have to do:
this.events.forEach(event => {
...similar code the above
})
本文标签: javascriptevents in fullcalendarVUE application not updatingStack Overflow
版权声明:本文标题:javascript - events in fullcalendarVUE application not updating - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744574946a2613564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论