artemsky / vue-snotify

Vuejs 2 Notification Center
https://artemsky.github.io/vue-snotify/
MIT License
795 stars 98 forks source link

Add SSR support #22

Open pedramk opened 6 years ago

pedramk commented 6 years ago

Great one! But I think it doesn't work with SSR. I'm using Nuxtjs and I couldn't add the plugin.

alexgarrettsmith commented 6 years ago

For anyone wondering, in the meantime, you can do this with Nuxt.js:

nuxt.config.js

plugins: [
  {
    src: './plugins/snotify',
    ssr: false
  }
],

plugins/snotify.js

import Vue from 'vue'
import Snotify, { SnotifyPosition } from 'vue-snotify'

const options = {
  toast: {
    position: SnotifyPosition.rightTop
  }
}

Vue.use(Snotify, options)

In your template:

<no-ssr>
  <vue-snotify></vue-snotify>
</no-ssr>

And finally, under build.extend:

config.resolve.alias['vue'] = 'vue/dist/vue.common'

Little hacky to get around this for now, but better than nothing πŸ‘

Thomas-Philippot commented 6 years ago

@alexgarrett I tryed you solution but nothing seems to work better.. The best I can have is object with only one install() method..

Edit : I was on the wrong template, it worked ! thank's

altynbek07 commented 4 years ago

@alexgarrett Hi. What is this code for? Is it still relevant? (nuxt@2.12.2)

config.resolve.alias['vue'] = 'vue/dist/vue.common'

By the way I did this (nuxt@2.12.2) and It works πŸ•ΊπŸ»: In nuxt.config.js:

plugins: [
    ...
    { src: '~/plugins/vue-snotify', mode: 'client' },
    ...
  ],

Create plugins/vue-snotify.js file with:

import Vue from 'vue'
import Snotify, { SnotifyPosition } from 'vue-snotify'

const options = {
  toast: {
    position: SnotifyPosition.rightTop
  }
}

Vue.use(Snotify, options)

In layouts/default.vue:

<template>
...
     <client-only>
          <vue-snotify></vue-snotify>
     </client-only>
...
</template>

And that's all, it works for me.

theprantadutta commented 4 years ago

@alexgarrett Hi. What is this code for? Is it still relevant? (nuxt@2.12.2)

config.resolve.alias['vue'] = 'vue/dist/vue.common'

By the way I did this (nuxt@2.12.2) and It works πŸ•ΊπŸ»: In nuxt.config.js:

plugins: [
    ...
    { src: '~/plugins/vue-snotify', mode: 'client' },
    ...
  ],

Create plugins/vue-snotify.js file with:

import Vue from 'vue'
import Snotify, { SnotifyPosition } from 'vue-snotify'

const options = {
  toast: {
    position: SnotifyPosition.rightTop
  }
}

Vue.use(Snotify, options)

In layouts/default.vue:

<template>
...
     <client-only>
          <vue-snotify></vue-snotify>
     </client-only>
...
</template>

And that's all, it works for me.

you need to add the styles. Add this line: import "vue-snotify/styles/material.css"