Cannot read properties of undefined (reading ‘parentNode‘)

Swiper:Cannot read properties of undefined (reading ‘parentNode’)问题

Cannot read properties of undefined (reading ‘parentNode‘)_第1张图片

问题:将swiper封装成组件,父组件调用

产生原因:实例化swiper的时候使用的css类名与父组件的某个类名重复。

//swiper组件
<template>
  <div class="homeSwiper">
    <div class="swiper-container crossHomeSwiper">
      <!-- 轮播位置 -->
      <div class="swiper-wrapper">
        <!-- 轮播内容插槽 -->
        <slot name="crossContent"></slot>
      </div>
      <!-- 轮播页数点点 -->
      <slot name="paginationCrossHome"></slot>
    </div>
  </div>
</template>
 mounted () {
    const crossHomeSwiper = new Swiper('.crossHomeSwiper', Object.assign(this.options, this.crossHomeOptions)) // eslint-disable-line no-unused-vars
    return crossHomeSwiper
  }
//引入swiper的父组件
<div class="crossHomeSwiper">
      <v-homeSwiper>
        <template #crossContent>
          <div class="swiper-slide">1</div>
          <div class="swiper-slide">2</div>
          <div class="swiper-slide">3</div>
          <div class="swiper-slide">4</div>
          <div class="swiper-slide">5</div>
        </template>
        <template #paginationCrossHome>
          <div class="swiper-pagination paginationNews"></div>
        </template>
      </v-homeSwiper>
</div>

父组件与封装组件都有crossHomeSwiper类名,且用该类名实例化,所以报错

你可能感兴趣的:(技术档案,javascript,前端,es6)