--问题--
你好,我不明白为什么滑动器不像自动播放必须启动。
当我查看(swiper)
事件中的swiper示例时,得到了以下结果:
- swiper.params.autoplay:
{delay: 1000, enabled: true}
- swiper.autoplay:
{ running: false, paused: false, pause: [Function], run: [Function], start: [Function], stop: [Function] }
它似乎滑动作为加载我的配置正确,但不会启动自动播放。
希望有人能理解为什么和帮助这个线程🙏。
--代码--
- 我在
NgModule
(home.module.ts)的导入中添加了SwiperModule
。*
主页.页面.ts
import { Component, OnInit } from '@angular/core';
import Swiper, { Autoplay } from 'swiper';
import { IonicSlides } from '@ionic/angular';
SwiperCore.use([ Autoplay, IonicSlides ]);
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: [ './home.page.scss' ]
})
export class HomePage implements OnInit {
swiperConfig = {
slidesPerView: 1,
spaceBetween: 0,
autoplay: {
delay: 1000
}
}
constructor() {}
ngOnInit() {}
}
主页.页面.html
<ion-content [fullscreen]="true">
<swiper direction="horizontal" [config]="swiperConfig">
<ng-template swiperSlide>Slide 1</ng-template>
<ng-template swiperSlide>Slide 2</ng-template>
<ng-template swiperSlide>Slide 3</ng-template>
<ng-template swiperSlide>Slide 4</ng-template>
</swiper>
</ion-content>
主页.页面.scss为空
2条答案
按热度按时间7tofc5zh1#
没有办法,同样的问题在这里。我是返回到旧的方式(不赞成),直到这个错误修复。旧的方式-〉使用旧的离子组件和
老办法-〉
并导入模板组件. html-〉
xxslljrj2#
For my Ionic 6 / Angular project, I needed to obtain a reference to the Swiper and then set the "running" property to true for it to actually start moving.
I.e. in your component HTML:
In your page.ts obtain the reference to that component:
And then:
Bit of a hack but it fixed it for me.