CroudTech / vue-fullcalendar

FullCalendar Wrapper for vue
MIT License
483 stars 100 forks source link

[Vue warn]: Error in mounted hook: "TypeError: rawSources.unshift is not a function" #90

Closed smingam closed 6 years ago

smingam commented 6 years ago

Hello, I just updated my project from 2.2.0 to 2.5.1 and got this error. I was using eventSources with a single object and it used to work, but now it needs an array.

Apparently, it's because events default to empty array, see here

events: {
    default() {
         return []
    },
},

And the way fullcalendar check the sources, see here

    let rawSources = this.opt('eventSources') || []
    let singleRawSource = this.opt('events')

    this.eventManager = eventManager

    if (singleRawSource) {
      rawSources.unshift(singleRawSource)
    }

Because events is never null, and if, like me you didn't use an array for :event-sources, the unshift is going to fail!

Hope it helps someone :)

BrockReece commented 6 years ago

Would it help if I removed the default for the events prop? I have not seen event-sources as a prop before either, I thought it had to be an array?

smingam commented 6 years ago

Well I don't know :) Currently, using event-sources, you always get an additional empty source in your eventSources array because of it. It doesn't seem to do anything bad so... At the same time, I don't know why I was using an object when the fullcalendar doc clearly say 'Array' for eventSources. I'm using a computed property that return the eventSource object (now array), so I probably mixed up events function, events and eventSources in my head! Thanks for your help!

BrockReece commented 6 years ago

No problem