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

Cannot read property 'show' of undefined | nuxt + vue-toasted #166

Closed dhust closed 4 years ago

dhust commented 4 years ago

If I add this.$toasted.show("Toasted !!") to doStuff() and do a hot reload, then it works.

If I add it and then press the refresh button on the browser, then it gives me the error: Cannot read property 'show' of undefined

Do I have to do an import or something? I just don't know why this.$toasted is undefined, especially when it works on a hot reload.

nuxt.config.js

plugins: [
  { src: '~/plugins/smooth-scroll', mode: 'client' },
  { src: '~/plugins/toasted', ssr: false },
],

plugins/toasted.js

import Vue from 'vue'
import Toasted from 'vue-toasted'

Vue.use(Toasted)

index.vue

methods: {
  doStuff() {
    this.$toasted.show("Toasted !!")
  }
}
shakee93 commented 4 years ago

Take a look at the docs on how to use it with nuxt : https://github.com/nuxt-community/modules/tree/master/packages/toast#usage

parthdevloper commented 3 years ago

Take a look at the docs on how to use it with nuxt : https://github.com/nuxt-community/modules/tree/master/packages/toast#usage

Still getting same error

Uncaught (in promise) TypeError: Cannot read property 'show' of undefined