我目前面臨的問題是,我能夠改變useRef<HtmlIonInputElement>的值,但當我進入輸入時,我無法洗掉文本。
我試著將const nameInput改為let nameInput,但這并不奏效。
誰能告訴我如何設定一個同樣可以用退格鍵洗掉的值?謝謝你。
import { IonPage, IonLabel, IonContent, IonInput, IonText, IonItem, IonList } from '@ionic/react'/span>;
import { useEffect, useRef } from 'react' ;
export const TestPage 2: React. FC = () => {
const nameInput = useRef<HTMLIonInputElement>(null)。
useEffect(() => {
if (nameInput.current) {
nameInput.current.innerText = "Kirito" ;
}
}, []);
return (
<IonPage>/span>
<IonContent fullscreen>/span>
< IonList lines="full" class="ion-no-margin ion-no-padding">
<IonItem>/span>
<IonLabel position="stacked">/span>
名稱輸入
</IonLabel>
< IonInput required type="text" ref={nameInput}> </IonInput>>
</IonItem>/span>
</IonList>/span>
</IonContent>/span>
</IonPage>/span>
);
}
uj5u.com熱心網友回復:
由于你正在使用React,最好使用UseState鉤子來操作你的變數。據我所知,你是想編輯IonInput標簽;在這種情況下,你不需要useRef。
export const TestPage2: React. FC = () => {
const [nameInput, setNameInput] = useState("Kirito, best swordman") 。
return (
<IonPage>
<IonContent fullscreen>/span>
< IonList lines="full" class="ion-no-margin ion-no-padding">
<IonItem>/span>
<IonLabel position="stacked">/span>
名稱輸入
</IonLabel>
< IonInput required type="text" onIonChange={(e: any) => setNameInput(e. detail.value)} value={nameInput}></IonInput>
</IonItem>/span>
</IonList>/span>
</IonContent>/span>
</IonPage>/span>
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/330239.html
標籤:

