【发布时间】:2020-03-19 14:07:48
【问题描述】:
我有一个 Ionic 4 项目,它已经实现了离子幻灯片。一切都很好,直到最近对 Ionic 进行了更新(不到一个月前),他们突然停止了工作。
在第一次加载时,它们似乎很好,但在之后的任何加载中:
- 寻呼机不工作或不显示
- 图片大小不正确
- 滚动有效,但不会像应有的那样将幻灯片对齐到中心
第一次加载有效: image of ion-slides as intended
第二次加载不会: image of ion-slides broken
没有错误消息或警告,截至 1 个月前,以下所有代码都运行良好,此后未进行任何更改。它只是随机坏了。
HTML:
<ion-slides #slides pager="true">
<ion-slide *ngFor="let option of options; let i = index">
<ion-card mode="md" [ngStyle]="{'background': borderColors[i]}">
<img style="object-fit: contain; border-radius: 20px; padding: 2px;" [src]="option.imageUrl">
</ion-card>
</ion-slide>
</ion-slides>
TS:
import { Component, Input, ViewChild } from "@angular/core";
import { IonSlides } from "@ionic/angular";
import { ContestOption } from "src/app/models/contest-model";
@Component({
selector: "app-results-swiper",
templateUrl: "./results-swiper.component.html",
styleUrls: ["./results-swiper.component.scss"]
})
export class ResultsSwiperComponent {
@Input() options = [
{ id: "null", imageUrl: "null", votes: 0 },
{ id: "null", imageUrl: "null", votes: 0 }
] as Array<ContestOption>;
@Input() borderColors = [];
@ViewChild("slides", null) slides: IonSlides;
constructor() {}
}
我尝试进一步隔离问题。这个 HTML 仍然失败:
<ion-slides #slides pager="true" [options]="slidesOpts">
<ion-slide>
Hello
</ion-slide>
<ion-slide>
Hello Again
</ion-slide>
</ion-slides>
重申一下,关于这个组件的一切都在不久前工作。然后,在最近的一次更新中,我开始在我的项目中看到 Ionic CSS 弃用警告。它们看起来像这样:
[DEPRECATED][CSS] Ionic CSS attributes are deprecated.
Replace:
'<div text-center>'
With:
'<div class="ion-text-center">'
自那次更新以来,离子滑梯坏了,决定停止工作。请帮忙!
【问题讨论】:
-
所以 ionic 4 中的滑块确实需要选项对象作为定义对象,例如寻呼机。你能分享你的滑块的选项对象吗?
-
滑块在没有选项的情况下仍然失败。在我的错误测试中,结果发现存在不同的问题。我会发布答案。
标签: angular ionic-framework ionic4 ion-slides