實際上,我正在創建一個前端,在其中我將手機號碼作為第一頁的輸入,然后在檢查手機號碼后我將轉到 OTP 頁面。在 OTP 頁面中,我將 otp 作為輸入,并且必須將 otp 和手機號碼發送到后端。我可以通過 otp,但不知道如何通過手機號碼,因為我已將其作為上一頁的輸入。這是注冊組件,它將接受手機號碼輸入import React from 'react';import './Signup.css';class Signup extends React.Component { constructor(props){ super(props); this.state={ mobile:'' } } onMobileChange = (event) => { this.setState({mobile: event.target.value}) } onSubmitSignup = () => { fetch('https://cors-anywhere.herokuapp.com/http://8080/signup/checkMobile',{ method:'post', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ mobile:this.state.mobile }) }) .then(response => response.json()) .then(data =>{ if(data.content === 'OK'){ this.props.loadNewUser(this.state.mobile); this.props.onRouteChange('otp','nonav'); } }) // this.props.onRouteChange('otp','nonav'); } render(){ const { onRouteChange} = this.props; return( <div className='container'> <div className='mt6'> <img src={require('./logo.png')} className='logoimg' alt='logo'/> </div> <h3 className='text-center b' style={{font:"Montserrat"}}>FOODVIRAAM</h3> <div>
如何在 React JS 中的兩個子組件之間傳輸數據?
POPMUISE
2023-02-24 16:50:54