Vue-awesome-swiper: Window undefined with Nuxt 1.0.0

Created on 1 Feb 2018  ·  12Comments  ·  Source: surmon-china/vue-awesome-swiper

Version

Nuxt : 1.0.0
Vue : 2.5.13
Swiper : 3.1.2

Steps to reproduce

  • Use vue-awesome-swiper with nuxt SSR installation from repository

What is Expected?

  • Running in Nuxt

What is actually happening?

  • Window is not defined
SSR

Most helpful comment

english please

All 12 comments

https://github.com/surmon-china/vue-awesome-swiper#mount-with-ssr

// If used in nuxt.js/ssr, you should keep it only in browser build environment
if (process.browser) {
  const VueAwesomeSwiper = require('vue-awesome-swiper/dist/ssr')
  Vue.use(VueAwesomeSwiper)
}

It's actually const VueAwesomeSwiper = require('vue-awesome-swiper/ssr') now as per docs

@bovas85 The docs has been updated after v3.0.0.

Ah yes, I noticed now. This was recent right? @surmon-china
Thanks.

@surmon-china 加了process.browser的判断,但是在组件引用import { swiper, swiperSlide } from 'vue-awesome-swiper/dist/ssr' 还是抛了window is not defined的错。是我的引入方式不对吗?

english please

@haryzxw 你的window is not defined 解决了么?我也刚遇到这个问题

@zhaoxiaoer888 嗯 解决了 当时也是参考了别人的解决方法 写法变了一下

@zhaoxiaoer888 嗯 解决了 当时也是参考了别人的解决方法 写法变了一下

怎么解决的?

I had a <no-ssr> as parent in the template. Removing that solved this for me on nuxt 2.0.
(It would worth adding a comment to the example, to omit that.)

Edit: then I figured that it is needed if you (most probably) have bindings of data available on the server side. To solve this, add a wrapper div between <no-ssr> and the div with the v-swiper:mySwiper directive on.

@paragonHex can you show exapmle. I have the same problem, but I can not solved it

Was this page helpful?
0 / 5 - 0 ratings