【问题标题】:modal reactjs close time模态reactjs关闭时间
【发布时间】:2020-06-06 02:31:55
【问题描述】:

我需要我的模态在一定时间后关闭,我该怎么做? 这就是我到目前为止所做的事情

import React from 'react';
import IconcloseModal from './../../assets/icon/icon-cerrar-modal.png';
import './Modal.css'

const Modal = ({ typeModal, textModal, showModal, positionModal, closeModal }) => {
    let titleModal = '';
    if (typeModal === 'success')
        titleModal = '¡Bien hecho!';
    else if (typeModal === 'warning')
        titleModal = '¡Cuidado!';
    return (
        <div>
            <div className={(showModal) ? 'notify ' + positionModal + ' do-show' : 'notify ' + positionModal}
                data-notification-status={typeModal}>
                <div className="content-warning">
                    <h3>{titleModal}</h3>
                    <p> {textModal}</p>
                </div>
                <div onClick={closeModal} className="close-alert"><img src={IconcloseModal} alt="Logo cerrar modal" /></div>
            </div>
        </div>
    )
}
export default Modal;

【问题讨论】:

    标签: javascript reactjs modal-dialog


    【解决方案1】:

    您可以为此使用 setTimout 函数。 假设closeModal 是一个函数,您可以像这样实现它。 这将在 3 秒后关闭模式。

    function close() {
      setTimeout(() => closeModal(), 3000)
    }
    return(
    ...
    <div onClick={close} className="close-alert"><img src={IconcloseModal} alt="Logo cerrar modal" /></div>
    ...
    )
    

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      相关资源
      最近更新 更多