taro父、子組件通信


父page

let personInfo = {
            mobile: this.state.mobile,
            email: this.state.email
 }
傳入自組件參數   personData={personInfo} 
<PersonInfo   personData={personInfo}  onHandleChange={this.handleInputChange.bind(this)}/>
 
 
子page
自組件傳到父組件 this.props.onHandleChange()比如你想傳一個布爾值就this.props.onHandleChange(false)
 handleMobileChange(e){
        console.log('----handleMailChange-----', this.state.mobile)
        this.setState({
            email: e.target.value
        },() => {
            this.props.onHandleChange({
                mobile: this.state.mobile,
                email: this.state.email
            })
        })
    }
 
<Input type='text' placeholder='請輸入手機號' value={personData.mobile} onChange={this.handleMobileChange.bind(this)} />
 
父page接收值(拿個手機舉例子)
 
handleInputChange(value){
     console.log('===888==我要接收==mobile===', value, '===email===')
     this.setState({
         mobile: value.mobile,
         email: value.email
     })
}
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM