useRef 返回一个可变的 ref 对象,其 .current 属性被初始化为传入的参数(initialValue)。返回的 ref 对象在组件的整个生命周期内保持不变。
示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="box"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/7.0.0-beta.3/babel.js"></script>
<script type="text/babel">
const {useRef} = React
function Compont() {
const username = useRef()
const password = useRef()
const handleClick = () => {
console.log('用户名:' + username.current.value)
console.log('密码:' + password.current.value)
}
return(
<div>
用户名:<input type="text" ref={username} /> <br/>
密码:<input type="password" ref={password} /> <br/>
<buttonBfwOnClick={handleClick}>点击登入</button>
</div>
)
}
ReactDOM.render( <Compont/>, document.getElementById('box'))
</script>
</body>
</html>
网友回复
glb三维模型有几种方式可以降低体积大小减少精度?
如何使用python PyTorch自己训练一个迷你版本的本地chatgpt聊天机器人?
three如何对三维glb模型实现精度降级内部结构清除只留外壳体积减小?
有没有免费根据图片音频视频素材按照文字提示自动剪辑修改图片音频视频素材生成网站的ai工具?
什么是:ContextGraph技术?
BIM模型太大如何在浏览器中通过three瘦身运行?
海量数据仓库选doris还是clickhouse?
js如何剥离去掉glb三维模型中的动画动作数据?
codex如何使用claude skills?
大疆无人机如何对室外风景区建筑进行3dgs的建模和浏览器交互预览效果?


