vue3-carousel icon indicating copy to clipboard operation
vue3-carousel copied to clipboard

SSR support?

Open andysay opened this issue 3 years ago • 12 comments

Hello ! This is project will be add ssr mode? now we have window is not defined

andysay avatar Oct 20 '21 06:10 andysay

I guess the carousel is by default SSR friendly since Window is used only inside onMounted hook check, could you give me a working example on the issue you are facing?

ismail9k avatar Oct 21 '21 17:10 ismail9k

Hello,

Having the same issue with nuxt 3 - everything is working alright, however, setting breakpoints throws errors (probably because you cannot access the window in SSR mode.)

lackoSK avatar Nov 12 '21 15:11 lackoSK

Hello, sorry but I'm very new on this, is any chance to have an example or documentation of this plugin installed on Nuxt 3 project?

ernestoreddi avatar Jan 27 '22 22:01 ernestoreddi

@ernestoreddi You can refer to the examples section in docs, it should work fine. Pleas let me know if you still have any other questions

ismail9k avatar Jan 29 '22 09:01 ismail9k

Hello ! This is project will be add ssr mode? now we have window is not defined

Nuxt provides the <ClientOnly> component for purposely rendering a component only on client side. To import a component only on the client, register the component in a client-side only plugin.

Use a slot as fallback until <ClientOnly> is mounted on client side.

      <template #fallback>
        <!-- this will be rendered on server side -->
        <p>Loading Carousel...</p>
      </template>

vinksz avatar Apr 28 '22 15:04 vinksz

If anyone is facing same issue, my temporary solution is here: https://github.com/ismail9k/vue3-carousel/issues/194#issuecomment-1402219199

ludioao avatar Jan 24 '23 16:01 ludioao

For Nuxt users, here is my fix:

  1. Rename your plugin filename.js to filename.client.js to make it a client-only render.
  2. In the component, just wrap your Carousel element with <ClientOnly> ... </ClientOnly>

sociojs avatar Feb 04 '23 07:02 sociojs

@t-bee do you mind sharing an example on the plugin and how to use it on the component?

jmdmacapagal avatar Feb 10 '23 09:02 jmdmacapagal

@t-bee do you mind sharing an example on the plugin and how to use it on the component?

Plugins --> vue3-carousel.client.js

import "vue3-carousel/dist/carousel.css";
import { Carousel, Slide, Pagination, Navigation } from "vue3-carousel";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component("Carousel", Carousel);
  nuxtApp.vueApp.component("Slide", Slide);
  nuxtApp.vueApp.component("Pagination", Pagination);
  nuxtApp.vueApp.component("Navigation", Navigation);
});

Component:

<ClientOnly>
    <Carousel :settings="settings" :breakpoints="breakpoints" :autoplay="2000" :wrap-around="true">
      <Slide v-for="(event, i) in eventList" :key="i">
        <div class="carousel__item">
          <div>#{{ i }} {{ event.title }}</div>
        </div>
      </Slide>
      <template #addons>
        <Navigation />
      </template>
    </Carousel>
  </ClientOnly>

sociojs avatar Feb 11 '23 08:02 sociojs

Hello,

Having the same issue with nuxt 3 - everything is working alright, however, setting breakpoints throws errors (probably because you cannot access the window in SSR mode.)

Did you ever get this working? I'm looking to add some conditions in the breakpoint object based on length of items.

KhalidT2 avatar Sep 15 '23 14:09 KhalidT2

See #326

signor-pedro avatar Nov 23 '23 19:11 signor-pedro

These SSR and breakpoint problems are solved with the new nuxt module: #326

erickfabiandev avatar May 14 '24 06:05 erickfabiandev