组件中未定义的渲染功能或模板:刷卡器

时间:2020-10-08 10:47:13

标签: javascript vue.js nuxt.js render swiper

我正在swiper中使用nuxt.js。我从他们的文档中尝试了该示例,但出现错误:

<template>
  <swiper
    :slides-per-view="3"
    :space-between="50"
    navigation
    :pagination="{ clickable: true }"
    :scrollbar="{ draggable: true }"
    @swiper="onSwiper"
    @slideChange="onSlideChange"
  >
    <swiper-slide>Slide 1</swiper-slide>
    <swiper-slide>Slide 2</swiper-slide>
    <swiper-slide>Slide 3</swiper-slide>
    ...
  </swiper>
</template>
<script>
// import Swiper core and required components
import SwiperCore, { Navigation, Pagination, Scrollbar, A11y } from 'swiper';

// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from 'swiper/vue';

// Import Swiper styles
import 'swiper/swiper.scss';
import 'swiper/components/navigation/navigation.scss';
import 'swiper/components/pagination/pagination.scss';
import 'swiper/components/scrollbar/scrollbar.scss';

// install Swiper components
SwiperCore.use([Navigation, Pagination, Scrollbar, A11y]);

// Import Swiper styles
export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  methods: {
    onSwiper(swiper) {
      console.log(swiper)
    },
    onSlideChange() {
      console.log('slide change')
    },
  },
};
</script>

浏览器错误 enter image description here

终端控制台中控制台中的警告 enter image description here

我的package.json enter image description here

2 个答案:

答案 0 :(得分:2)

Swiper docs状态:

滑动Vue.js组件仅与新的Vue.js版本3兼容。

Nuxt 2.x当前使用Vue 2,这会导致您提到的错误。一种解决方法是将Swiper的API与HTML结合使用,如以下组件所示:

get()

答案 1 :(得分:0)

如果您使用的是较新版本的nuxtjs,请将容器包装在<client-only></client-only>中。将<no-ssr></no-ssr>用于旧版本