[英]Swiper slide is not displaying in ionic 5.7
I have created Ionic-Angular PWA.I have updated the ionic version to 5.7.0.我已经创建了 Ionic-Angular PWA。我已经将 ionic 版本更新为 5.7.0。 As per this new updation I am trying to replace the ion-slides with swiper-slide as the ion-slides has been deprecated.
根据这个新的更新,我试图用 swiper-slide 替换 ion-slides,因为 ion-slides 已被弃用。
swiper : 6.8.4刷卡:6.8.4
ionic : 5.7.0离子:5.7.0
angular : 12.0.2角度:12.0.2
In my code在我的代码中
app.module.ts app.module.ts
import { SwiperModule } from 'swiper/angular';
@NgModule({
imports: [SwiperModule],
})
component.ts组件.ts
import SwiperCore, { Navigation, Pagination } from 'swiper';
import { IonicSwiper } from '@ionic/angular';
SwiperCore.use([IonicSwiper, Navigation, Pagination]);
export class GenesisPage implements OnInit {
slideOpts = {
initialSlide: 0,
speed: 400,
loop: true,
autoplay: {
disableOnInteraction: false
},
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet(index, className) {
const newClass = `${className} myCustomPager`;
return `<span class="${newClass}"></span>`;
}
}
}; };
component.html组件.html
<swiper [pagination]="slideOpts.pagination" [initialSlide]="slideOpts.initialSlide"
[speed]="slideOpts.speed" [loop]="slideOpts.loop" [autoplay]="slideOpts.autoplay">
<swiper-slide>
<div class="image-wrapper">
<img loading="lazy" *ngIf="!webp" width="640" height="360"
src="assets/images/genesis/launch-slide-1-new.png" class="first" alt="launch slide"
useImg />
<img loading="lazy" *ngIf="webp" width="640" height="360"
src="assets/images/genesis/launch-slide-1-new.webp" class="first" alt="launch slide"
useImg />
</div>
<div class="slide-content-wrap">
<h2>DISCOVER</h2>
<p>& EXPLORE</p>
</div>
</swiper-slide>
</swiper>
I am getting the error as below我收到如下错误
Can anyone please help me out for this.任何人都可以帮我解决这个问题。 Thanks in advance.
提前致谢。
I was facing the same issue.我面临着同样的问题。 Try importing the 'SwiperModule' in the module file of your Ionic page instead of the main 'app.module.ts'
尝试在 Ionic 页面的模块文件中导入“SwiperModule”而不是主“app.module.ts”
// page-name.module.ts
import { SwiperModule } from 'swiper/angular';
@NgModule({
imports: [SwiperModule],
})
Ive found swiper-slide not to work so I am using the following as per Swiperjs.com我发现 swiper-slide 不起作用,所以我按照 Swiperjs.com 使用以下内容
<swiper
[pagination]="{type: 'fraction'}"
[navigation]="true"
class="mySwiper">
<ng-template swiperSlide>Slide 1</ng-template>
<ng-template swiperSlide>Slide 2</ng-template>
<ng-template swiperSlide>Slide 3</ng-template>
</swiper>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.