nuxt.js 使用vue-awesome-swiper提示getComputedStyle' on 'Window': parameter 1 is not of type 'Element'?

image.png
nuxt.js 使用vue-awesome-swiper提示Failed to execute getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

代码如下:

<div
      class="swiper-wrapper gallery-top"
      v-swiper:swiperTop1="swiperOptionTop"
      ref="swiperTop"
      @slideChange="onSlideChange"
    >
      <div class="swiper-slide" v-for="item in showImgs()" :key="item.id">
        <img :src="item.picUrl" @click="openNewWindow(item.forward)" class="gallery-img" />
      </div>
    </div>

网上有人说class需要使用swiper-wrapper,但是还不行,@slideChange="onSlideChange"也没出发

阅读 1.5k
2 个回答

SSR 的时候,程序运行在服务器端,没有 window,自然会报错。

类似 swiper 这种依赖浏览器的库,还有各类图表,就要放弃 SSR。最简单的做法是在外面包一层 <client-only>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题