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

With Nuxt.js #75

Closed
epartipilo opened this issue Jul 12, 2017 · 16 comments
Closed

With Nuxt.js #75

epartipilo opened this issue Jul 12, 2017 · 16 comments

Comments

@epartipilo
Copy link
Contributor

Hi,

Is there any way to this awesome component with Nuxt.js?

Right now I have this on plugins/ directory,
this {src: '~plugins/vue-slider-component', ssr: false} on nuxt.config.js,
and this <vue-slider ref="slider" v-model="price"></vue-slider> on my template but it's not rendering the component.

The only way I get to render it is importing the component on the template, it show the component the first time and works but when reloading the page it gives me de server window not defined error.

Thanks!

@NightCatSama
Copy link
Owner

Component does not support the SSR, because the component used document when the component is initialized.

@epartipilo
Copy link
Contributor Author

Hi @NightCatSama, I managed to get it working for client-side only.
I insisted because I consider you did a great job.
If you want I can add this hack to your README file just to give an option for users to try it out.

With the help of this tutorial https://alligator.io/vuejs/hide-no-ssr/ to keep client and server DOM equal and Nuxt.js proposal for window undefined https://nuxtjs.org/faq/window-document-undefined.

Seems prety good in 'dev' mode, I have not prove it on production yet.

Cheers!

@NightCatSama
Copy link
Owner

It's great, welcome to give your pr to modify the README file.

@cdiaz
Copy link

cdiaz commented Jul 23, 2017

@epartipilo You can share your Hack ?

@epartipilo
Copy link
Contributor Author

@NightCatSama I already have the Readme.md updated in a new branch but I don't have the permission to make the push and pr.
@cdiaz I'm waiting for @NightCatSama to give me permissions to submit the README update for the hack

Cheers!

@NightCatSama
Copy link
Owner

@epartipilo You have to fork the project down and then submit pr to me.

@maicong
Copy link

maicong commented Jul 25, 2017

@epartipilo Did you register the component correctly? Like this:

~plugins/vue-slider-component.js

import Vue from 'vue'
import VueSlider from 'vue-slider-component'

Vue.component('vue-slider', VueSlider)

nuxt.config.js

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

test.vue

<template>
  <vue-slider ref="slider" v-model="price"></vue-slider>
</template>

@epartipilo
Copy link
Contributor Author

Hello @maicong
No, I didn't because I don't know why it wasn't working, I was not sure if it was some Nuxt bug.
What I did was:

//  load library just for client side
if (process.BROWSER_BUILD) {
    let VueSlider = require('vue-slider-component')
    components['vue-slider'] = VueSlider
}

in the .vue file where I used it

@epartipilo
Copy link
Contributor Author

Hello @maicong , I just updated the README file to explain the hack for using it with Nuxt.
If you have a cleaner solution please let me know.

Cheers

@LeCoupa
Copy link

LeCoupa commented Aug 4, 2017

@maicong I tried your solution but did not work for me. Still getting:

[vue-router] Failed to resolve async component default: ReferenceError: document is not defined

@alistat
Copy link

alistat commented Sep 24, 2017

Hello, everyone! And thanks @epartipilo for the solution :)
It seems that "process.BROWSER_BUILD" is now replaced with "process.browser"
Check again here https://nuxtjs.org/faq/window-document-undefined
("process.BROWSER_BUILD" was always undefined for me...)

@tschut
Copy link

tschut commented Dec 6, 2018

@epartipilo Did you register the component correctly? Like this:

~plugins/vue-slider-component.js

import Vue from 'vue'
import VueSlider from 'vue-slider-component'

Vue.component('vue-slider', VueSlider)

nuxt.config.js

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

test.vue

<template>
  <vue-slider ref="slider" v-model="price"></vue-slider>
</template>

This solution works for me! Thanks a lot :)

@ramigs
Copy link

ramigs commented Dec 31, 2019

don't forget also to add the CSS in one of these ways:

  1. globally, in nuxt.config.js

css: [ '~/assets/sass/main.scss', '~/assets/icons/main.css', 'swiper/css/swiper.css', 'vue-slider-component/theme/antd.css' ],

  1. in vue-slider-component.js

import 'vue-slider-component/theme/antd.css'

  1. or, in your component or page

import 'vue-slider-component/theme/antd.css'

@Spani4
Copy link

Spani4 commented Aug 5, 2021

@epartipilo Did you register the component correctly? Like this:

~plugins/vue-slider-component.js

import Vue from 'vue'
import VueSlider from 'vue-slider-component'

Vue.component('vue-slider', VueSlider)

nuxt.config.js

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

test.vue

<template>
  <vue-slider ref="slider" v-model="price"></vue-slider>
</template>

I registered plugin as described but I still had to wrap it with in order to get it rendered and avoid error related to mismatch of client and server rendered DOM. Hope it might be helpful

@Aybee5
Copy link

Aybee5 commented Jul 27, 2022

Has anyone tried using this with Nuxt 3?
I have tried all the options above with Nuxt 3 implementations, and it's not working

@jonmes
Copy link

jonmes commented Aug 4, 2023

Has anyone tried using this with Nuxt 3? I have tried all the options above with Nuxt 3 implementations, and it's not working

Have you figure out a way to import it in nuxt 3

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