euvl / vue-js-toggle-button

:fish_cake: Vue.js 2 toggle / switch button - simple, pretty, customizable
http://vue-js-toggle-button.yev.io/
MIT License
934 stars 133 forks source link

How to use it in Nuxt.js #112

Open yeahliv opened 5 years ago

yeahliv commented 5 years ago

ReferenceError document is not defined

i think it because nuxt load dist/index.js , not load'dist/ssr.index.js

yeahliv commented 5 years ago

ok, it work, set ssr: false

plugins: [
    { src: '~/plugins/vue-js-toggle-button.js', ssr: false }
  ],
cranx commented 5 years ago

But with ssr: false it means plugin doesn't support ssr, plugin should be updated and shouldn't refer to document when running on server side

EdwinHoksberg commented 5 years ago

What worked for me was including the generated ssr dist file instead of the default. I don't know how or why a separate file is generated but it works for me 🤷‍♂

For example in a nuxt plugin: Before:

import Vue from 'vue';
import VueJsToggleButton from 'vue-js-toggle-button';

Vue.use(VueJsToggleButton);

After:

import Vue from 'vue';
import VueJsToggleButton from 'vue-js-toggle-button/dist/ssr.index';

Vue.use(VueJsToggleButton);
DSoftwareArtist commented 5 years ago

Not working when I run nuxt start

antoinevulcain commented 4 years ago

@EdwinHoksberg You saved my day! if you need anything from my API let me know!

vesper8 commented 4 years ago

@euvl @EdwinHoksberg's solution of loading vue-js-toggle-button/dist/ssr.index should be added to the SSR part of the readme, without it you have to disable SSR or you run into a document is not defined error

hapetherw commented 3 years ago

Not working when I run nuxt start

It's the same issue. Is there any solution?