标签:div ops rgb nts def span cli 属性 pre
//父组件 const LayoutMain = ()=>{ const [flowImg,setFlowImg] = useState(false); const openModal = ()=>{ setFlowImg(true) console.log(flowImg); } const handleOk = ()=>{ setFlowImg(false) } const handleCancel = ()=>{ setFlowImg(false) } return(<div> <button onClick={openModal}>打开modal</button> <FlowImg handleOk={handleOk} handleCancel={handleCancel} isModalVisible={flowImg}/> //属性传值/传事件 </div>) } export default LayoutMain; //子组件 const FlowImg =(props)=>{ const { isModalVisible, handleOk,handleCancel} = props;//子组件 用props 接收值和事件 return(<div> <Modal title="Basic Modal" visible={isModalVisible} onOk={handleOk} onCancel={handleCancel}> <p>Some contents...</p> <p>Some contents...</p> <p>Some contents...</p> </Modal> </div>) }
标签:div ops rgb nts def span cli 属性 pre
原文地址:https://www.cnblogs.com/zhaozhenzhen/p/14360506.html