访问react 最新dom 一般情况我们这样即可,这样不能检测dom的挂载和卸载 const textInput = useRef(null); 可以使用方法传递给ref const ref = e => { // React 将在组件挂载时,会调用 ref 回调函数并传入 DOM 元素,当卸载时调用它并传入 null dataRef.current.div = e; setMounted(!!e); }; <div style={style} ref={ref} > 。。。。 </div>