eolant / vuetify-toast-snackbar

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

Possible to call toast out of this context? #1

Closed lorro closed 5 years ago

lorro commented 5 years ago

Hi,

I wondered if it's possible to call the toast methods without having to go through the 'this' context but with a static method or so? I would like to call this in a vuex plugin, but the 'this' context doesn't have the $toast property here unfortunately.

Thanks.

eolant commented 5 years ago

The easiest way to call toast from Vuex would be to import app there. First you need to export app in the module where you init it: export const app = new Vue(...)

And then if you want to call it outside of Vue context: import { app } from '~/app'

And call toast: app.$toast.info('Hello!')

You might need to check the import path as I gave an example from my Laravel Vuetify repo.

lorro commented 5 years ago

Thanks for pointing that out for me :) That works perfectly.