我正在使用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>
完成内容加载后,您可以使用.scrollToBottom()
。这是ion-content
的方法。