为什么我会得到"Attempted import error: 'EffectCards' is not exported from 'swiper'"?



我正在使用Create React App,并且已经按照文档所说的方式导入,因为Create React应用程序还不支持纯ESM包。

import { EffectCards } from "swiper";
import { Swiper, SwiperSlide } from "swiper/react/swiper-react.js";

但我得到了错误:Attempted import error: 'EffectCards' is not exported from 'swiper'.

EffectFade效果很好,为什么不使用EffectCards呢?使用Create React应用程序从哪里导出?

官方文件指出:"默认情况下,SwiperReact使用核心版本的Swiper(没有任何附加组件(。如果你想使用导航、分页和其他组件,你必须先安装它们">

安装它们:

import SwiperCore, { EffectFade, EffectCards } from "swiper";
SwiperCore.use([EffectFade, EffectCards]);

在我的案例中("swipper":"^8.2.2"(更改导入语句有助于

import { Swiper, SwiperSlide } from 'swiper/react/swiper-react.js';
import 'swiper/swiper.scss'; // core Swiper
import 'swiper/modules/effect-cards/effect-cards.scss';
import { EffectCards } from "swiper";

相关内容

最新更新