Ionic 4 React从页面底部开始

问题描述 投票:0回答:1

我正在使用Ionic 4 React,并尝试制作一个简单的聊天应用程序。当用户加载聊天页面时,我想自动从页面底部开始。最简单的方法是什么?

这是我的代码:

<IonPage>
        {/* Header */}
        <IonHeader>
            <IonToolbar>
            <IonButtons slot="start">
            <IonButton onClick={() => {
                setCurrentConversationId('')
                setState('home');
            }}
            fill="clear"  className="back-button" shape="round" size="default">
                <IonIcon slot="icon-only" icon={arrowBack} />
            </IonButton>
            </IonButtons>
            <IonTitle>Chat</IonTitle>
            </IonToolbar>
        </IonHeader> 

        {/* Content */}
        <IonContent>        
            {Object.values(messages).map((el, idx) => 
                printMessage(el, idx)
            )}
        </IonContent>

    </IonPage>
ionic-framework ionic4 ionic-react
1个回答
0
投票

完成内容加载后,您可以使用.scrollToBottom()。这是ion-content的方法。

© www.soinside.com 2019 - 2024. All rights reserved.