shakee93 / vue-toasted

🖖 Responsive Touch Compatible Toast plugin for VueJS 2+
https://shakee93.github.io/vue-toasted/
MIT License
2.21k stars 194 forks source link

Calling goAway() on global toast causes "Cannot read property 'includes' of undefined" and toast does not clear #38

Closed esmsnt closed 7 years ago

esmsnt commented 7 years ago

It looks like the instance.cached_options object is empty on global toasts.

For the moment I just modified the if in _goAway to check if position is defined and avoid the error: if (instance.cached_options.position && instance.cached_options.position.includes('bottom')) {

This is the definition of the global toast done in main.js right after setting up Toasted.

Vue.use(Toasted, {
  position: 'top-right',
  duration: 5000,
  theme: 'primary'
})
Vue.toasted.register('cookieNotification',
  (thisVue) => {
    // Use thisVue instance to resolve some routes in here
    var toastContent = 'some notification content'
    return toastContent
  },
  {type: 'info',
    position: 'bottom-right',
    duration: null,
    className: 'cookie-alert',
    onComplete: function () {
      var d = new Date()
      d.setTime(d.getTime() + (14 * 24 * 60 * 60 * 1000))
      var expires = 'expires=' + d.toUTCString()
      document.cookie = 'cookieNotice=true;' + expires + ';path=/'
    },
    action: {
      text: 'X',
      onClick: (e, toastObject) => {
        var d = new Date()
        d.setTime(d.getTime() + (14 * 24 * 60 * 60 * 1000))
        var expires = 'expires=' + d.toUTCString()
        document.cookie = 'cookieNotice=true;' + expires + ';path=/'
        toastObject.goAway(0)  //This is where the issue occurs
      }
    }
  }
)
shakee93 commented 7 years ago

Thanks. will be fixed in the coming version.