ref用法(获取元素节点)
import React from 'react'
export default class App extends React.Component {
    myref=React.createRef()
    render() {
        return (
            
            <div>
                {/* 获取输入框的内容 写法一 */}
                <input ref="mytext"></input>
                  <button onClick={
                    ()=>{
                        console.log(this.refs.mytext.value)   
                    }
                }>add 匿名函数触发</button>
                {/* 获取输入框的内容 写法二 */}
                <input ref={this.myref}></input>
                  <button onClick={
                    ()=>{
                        console.log(this.myref.current.value)   
                    }
                }>add 匿名函数触发</button>
            </div>
        )
    }
}
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号