zoukankan      html  css  js  c++  java
  • taro中子父传值

    其实网上很多方法,我这只是一个简单的demo,废话不多说直接上代码

    import Taro, { Component } from '@tarojs/taro'
    import { View, Text } from '@tarojs/components'
    import './index.less'
    
    //子组件
    class Child extends Component{
      constructor(props) {
        super(props);
        this.state = ({
            
        })
      }
      handleVal (event) {
        this.props.handleEmail(event.target.value);
      }
    
      render (){
          return (
              <div>
                    请输入邮箱:<input style="200px;height:30px;font-size:18px;" ref="emailDom" onChange={this.handleVal.bind(this)} />
              </div>
          )
      }
    };
    
    export default class Index extends Component {
      constructor(props) {
        super(props);
        this.state = {
          email:"火星黑洞"
        }
      }
      handleEmail1(date){
        this.setState({
          email:date
        })
      }
      
    
      config = {
        navigationBarTitleText: '首页'
      }
    
      componentWillMount () { }
    
      componentDidMount () { }
    
      componentWillUnmount () { }
    
      componentDidShow () { }
    
      componentDidHide () { }
    
      render () {
        return (
          <div className='index'>
            <h3>子父传值</h3>
            <Child name="email"  handleEmail={this.handleEmail1.bind(this)}/>
            <div>用户邮箱:{this.state.email}</div>
          </div>
        )
      }
    }

    然后执行:cnpm run dev:h5

    页面效果是:

  • 相关阅读:
    等宽布局和flex
    antd按需加载
    linux-redis cluster集群(redis5.x)
    linux-mysql-主从同步
    mysql-行转列
    Spring Bean 作用域
    ArrayList、LinkedList区别(jdk8)
    java类及实例初始化顺序
    线程池-结构
    GIT基础
  • 原文地址:https://www.cnblogs.com/ldlx-mars/p/10159552.html
Copyright © 2011-2022 走看看