跳转到内容
返回

在react中获取Dom

在react中获取Dom节点

用到的api:

代码

// demo组件
import { createRef } from "react";
const Demo = () => {
  const Dom_P = createRef(null);
  const getDom = () => {
    console.log(Dom_P); //{current:p}
    console.log(Dom_P.current); // <p>This is P</p>
  };
  return (
    <div>
      <p ref={Dom_P}>This is P</p>
      <button onClick={getDom}>Get P</button>
    </div>
  );
};
export default Demo;


上一篇
antd menu组件
下一篇
关于hexo打包路径问题