Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR options #31

Closed
Markvandersteen opened this issue Nov 27, 2017 · 8 comments
Closed

SSR options #31

Markvandersteen opened this issue Nov 27, 2017 · 8 comments

Comments

@Markvandersteen
Copy link

Markvandersteen commented Nov 27, 2017

Hello thanks for the package, already using it in one of my projects.
I do have a question however.

Is there a way to use this package with ssr/nuxt?
If so it would be awesome if the readme contained an example, if not is something that is going to be added?

@imcvampire imcvampire changed the title SRR options SSR options Nov 27, 2017
@imcvampire
Copy link
Collaborator

imcvampire commented Nov 27, 2017

Hi @Markvandersteen,

I use this package with SSR and it works perfectly! What problem do you face now?

Just import it, use it as normal, you don't need any special code!

@Markvandersteen
Copy link
Author

Markvandersteen commented Nov 27, 2017

screen shot 2017-11-27 at 16 32 19
At the moment i'm getting some window not defined errors.

@Markvandersteen
Copy link
Author

Markvandersteen commented Dec 1, 2017

I got it working, i did need some extra code to make it work with nuxtjs.

@miottid
Copy link

miottid commented Dec 12, 2017

Hi, @Markvandersteen what is the extra code you've added in order to get it work.

@lexcode
Copy link

lexcode commented Dec 13, 2017

Hey @Markvandersteen I am getting the same issue, could you paste your extra code solution in nuxt please?

@lexcode
Copy link

lexcode commented Dec 13, 2017

I found it,

plugins/lightbox.js

if (process.BROWSER_BUILD) {
  const VueTouch = require('vue-touch')
  Vue.use(VueTouch, { name: 'v-touch' })
}

nuxt.config.js

build: {
    vendor: ['vue-touch'],
}

@Markvandersteen
Copy link
Author

@dmiotti @lexcode My approach was to use the System.import function.
When the component is mounted. I import the things I need.


 async loadLightBox() {
        Promise.all([
          System.import('vue-touch'),
          System.import('vue-lazyload'),
          System.import('vue-image-lightbox')
        ]).then((modules) => {
          const VueTouch = modules.shift(),
            VueLazyLoad = modules.shift(),
            LightBox = modules.shift();


          Vue.use(VueTouch, {name: 'v-touch'});
          Vue.use(VueLazyLoad);
          Vue.component('lightbox', LightBox);
          this.lightboxReady = true;
        });
      },
    },
    async mounted() {
      this.loadLightBox();
    }
`

@sven-ra
Copy link

sven-ra commented Feb 20, 2019

Edited for updated nuxt and vue-image-lightbox

An easy way to use it in Nuxt is like this:

Make a plugin file:

import Vue from 'vue'
import VueLazyLoad from 'vue-lazyload'
import LightBox from 'vue-image-lightbox'
require('vue-image-lightbox/dist/vue-image-lightbox.min.css')

Vue.use(VueLazyLoad)
Vue.component('light-box', LightBox)

Add the plugin to nuxt.config with SSR disabled:

plugins: [
  {
    src: '~/plugins/vue-lightbox-plugin.js',
    ssr: false
   }
 ]

Now you can use the 'light-box' component globally. It works only after you have mounted your component:

<template>
  <client-only>
    <light-box :images="lightBoxImages" />
  </client-only>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants