eolant / vuetify-toast-snackbar

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

Inject in Nuxt context #5

Closed votintsev closed 5 years ago

votintsev commented 5 years ago

Hello.

Do you have idea how I can inject you package in nuxt context. I tried created plugin like:

import Vue from 'vue'
import VuetifyToast from 'vuetify-toast-snackbar'

Vue.use(VuetifyToast, {
  x: 'right',
  y: 'top',
  color: 'info',
  icon: 'info',
  timeout: 3000,
  dismissable: true,
  autoHeight: false,
  multiLine: false,
  vertical: false,
  shorts: {
    custom: {
      color: 'purple',
    },
  },
  property: '$toasted',
})

export default function (ctx, inject) {
  inject('toast', Vue.prototype.$toasted)
}

inspired: https://github.com/nuxt-community/modules/blob/master/packages/toast/plugin.js

But it doesn't work :(

eolant commented 5 years ago

Hi, sorry took me some time to take a look at it. It's pretty simple, put this in plugins/vuetify.js:

import Vue from 'vue'
import Vuetify, { VSnackbar } from 'vuetify/lib'
import VuetifyToast from 'vuetify-toast-snackbar'

Vue.use(Vuetify, {
  components: {
    VSnackbar
  }
})

Vue.use(VuetifyToast)
votintsev commented 5 years ago

Hi, @eolant . Thanks for the answer. But you provide solution not for my question. I need Combined inject.

eolant commented 5 years ago

Sorry @votintsev , I misunderstood. Please try example from nuxt documentation:

export default ({ app }, inject) => {
  inject('toast', Vue.prototype.$toasted)
}

It works for me and I'm able to call toast from store context too. Note that you'll still need my previous answer to define VSnackbar component. Just add export at the end of the file.