码迷,mamicode.com
首页 > 其他好文 > 详细

React的三种用法

时间:2019-10-03 12:50:51      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:用法   let   reac   color   code   bsp   nbsp   component   class   

import React, { Component } from "react"
export default class MyInput extends Component {
    

    // 第一种
    getvalue11= () => {
        let hah = this.refs.zhi.value
        console.log("第1种", hah)
    }
  
    // 第2种 ref的使用
   getvalue=()=>{
       console.log(this.input1.value)
   }
     
    Valuerefs = React.createRef();//创建一个承装ref的容器  这个容器是专门的  只能保存一个ref  Myrefs一致  
    getvalue22=()=>{
        let pwd = this.Valuerefs.current
        console.log("第三种", pwd.value)
    }

    render() {
        return (
            <div>


                {/* 第一种 */}
                <input type="text" ref="zhi"></input>
                <button onClick={this.getvalue11}>按钮</button>    

                {/* 第二种  this.input1的实例是input*/}
                <input type="text" ref={(input)=>{this.input1=input}}></input>
                <button onBlur={this.getvalue}>按钮</button>
                 

                 {/* 第三种 */}
                <input type="text" ref={this.Valuerefs}></input>
                <button onClick={this.getvalue22}>按钮</button>


            </div>
        )
    }
}

 

React的三种用法

标签:用法   let   reac   color   code   bsp   nbsp   component   class   

原文地址:https://www.cnblogs.com/IwishIcould/p/11619473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!