Ionic V4 (angular) content.scrollToTop

Lar*_*ing 6 ionic-framework angular ionic4

在 Ionic V3.X 中,这会将视图滚动到顶部:

@ViewChild(Content) content: Content;

this.content.scrollToTop();
Run Code Online (Sandbox Code Playgroud)

在 Ionic V4 中,这不再有效 - 'Property scrollToTop 在类型内容上不存在'。

有替代方案吗?谢谢。

Gle*_*leb 6

@ViewChild(IonContent) content: IonContent;

...

this.content.scrollToTop(500);
Run Code Online (Sandbox Code Playgroud)

它对我有用,希望它也能帮助你。欲了解更多详情https://www.freakyjolly.com/ionic-4-how-to-scroll-to-top-bottom-using-ion-content-scroll-events/


seb*_*ras 2

似乎该方法是在v4.0.0-beta.3scrollToTop()中添加的,但几个小时前在v4.0.0-beta.6中修复了一些问题,因此请将 Ionic 更新到beta.6版本,该方法应该在那里可用。scrollToTop()

编辑

谢谢,但我已经使用了 V4.0.0-beta.6。检查API,显然不再有scrollToTop()。

我很抱歉坚持,但我刚刚安装了 V4.0.0-beta.6,并且可以scrollToTop()毫无问题地使用该方法:

在此输入图像描述

在此输入图像描述

  • @phunder我能够通过像这样“import { IonContent } from '@ionic/angular';”导入它,然后获取参考:“@ViewChild(IonContent) content: IonContent;”然后调用这样的方法:`this.content.scrollToTop(500);`。 (5认同)