参考:https://blog.csdn.net/weixin_44207333/article/details/103860630
如果之前安装过swiper,请先删除
yarn remove swiper
使用
yarn add @types/swiper
// 引入 import Swiper from 'swiper'; import 'swiper/css/swiper.min.css' // 使用 参考 https://www.jianshu.com/p/341b48019ad7 componentWillUnmount() { if (this.swiper) { // 销毁swiper this.swiper.destroy() } } componentDidUpdate(){ if(this.swiper){ this.swiper.slideTo(0, 0) this.swiper.destroy() this.swiper = null; } this.swiper = new Swiper(this.refs.lun, { loop:true, pagination: { el: '.swiper-pagination', clickable: true, }, }); }