40 lines
1.1 KiB
HTML
40 lines
1.1 KiB
HTML
<!--
|
|
* @Author: chenxuan
|
|
* @Date: 2022-01-02 21:23:11
|
|
* @LastEditTime: 2022-03-28 23:24:12
|
|
* @LastEditors: chenxuan
|
|
-->
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>回调函数形式的refs属性</title>
|
|
</head>
|
|
<body>
|
|
<div id="app"></div>
|
|
<script src="../package/old/react.development.js"></script>
|
|
<script src="../package/old/react-dom.development.js"></script>
|
|
<script src="../package/old/babel.min.js"></script>
|
|
<script type="text/babel">
|
|
class Demo extends React.Component{
|
|
haha1=()=>{
|
|
const {haha}=this;
|
|
alert(haha.value);
|
|
}
|
|
render(){
|
|
return(
|
|
<div>
|
|
{/*这种内联函数,更新会多次调用 时有bug */}
|
|
<input type="text" ref={(c)=>this.haha=c}/>
|
|
<button onClick={this.haha1}>点我</button>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
ReactDOM.render(
|
|
<Demo/>,document.getElementById('app')
|
|
)
|
|
</script>
|
|
</body>
|
|
</html> |