eolant / vuetify-toast-snackbar

Basic Vue toast service that uses Vuetify Snackbar component.
MIT License
127 stars 36 forks source link

Plugin doesn't work #22

Closed 5E1EMENT closed 4 years ago

5E1EMENT commented 4 years ago

Hello. I want to use your plugin, but i have an error in my console when i emit it like: this.$toast('Default toast'). I installed it correct in main.js: import VuetifyToast from 'vuetify-toast-snackbar' Vue.use(VuetifyToast)

There is an error: Error in v-on handler: "TypeError: this.$toast is not a function" I tried to emit this toast from my component by click. Why this error happens?

eolant commented 4 years ago

@5E1EMENT this isn't available in template context. Use $toast or move your call into method.

5E1EMENT commented 4 years ago

I call this.$toast('Default toast') from method

eolant commented 4 years ago

@5E1EMENT can you please recreate your set up in the sandbox? I don't have enough information to help you.

5E1EMENT commented 4 years ago

I placed the code in the dialog file: https://codesandbox.io/s/vuetify-playground-mu582

eolant commented 4 years ago

@5E1EMENT Oh, you are calling methods yourself without binding them to correct context (Vue.js does it for you normally). Try this:

this.$options.methods[item.method].call(this, router)