zoukankan      html  css  js  c++  java
  • 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
         })
    }
     
     
     
  • 相关阅读:
    AJAX和DHTML
    解析xml的4种方法详解
    javascript -window与document 待整理
    JavaScript中的shift()、unshift()和pop()函数
    JS中如何定义全局变量
    j中的substr(start,length)和substring(start,stop)
    JS中的唯一容器:数组
    typeof()和instanceof的用法区别
    JS和DOM的关系
    jQuery对象与DOM对象之间的转换方法
  • 原文地址:https://www.cnblogs.com/pikachuworld/p/11726310.html
Copyright © 2011-2022 走看看