弹框外部点击关闭
import React, { useLayoutEffect, useRef } from 'react' export default function ceshi() { const as = useRef(null) const handleCl =()=>{ window.addEventListener("click", (e) => { if (e.target != as.current) { console.log(e.target); } }); } useLayoutEffect(() => { handleCl() }, []); return ( <div> <div style={{width:'100px',height:'100px',border:"1px solid red"}}></div> <button>点击</button> </div> ) }
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/17407497.html