亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

引導 3 模態在反應關閉按鈕

引導 3 模態在反應關閉按鈕

慕沐林林 2022-08-18 10:33:20
我在 react 項目中使用 bootstrap 3。在我的項目中,我創建了一個顯示模態div的組件。我將在不同的父組件中使用此組件。模態在延時后顯示。模態顯示良好,但不會消除。關閉按鈕也不起作用。父組件import React, { Component } from 'react';import Timer from './timer';class Parent extends Component {    render() {        return (            <div>                <Timer />            </div>        ); }    }export default Parent;子組件import React, { Component } from 'react';class Timer extends Component {    constructor(props){        super(props);        this.state = {            fin: false        }    }    componentDidMount(){        this.myInterval = setInterval(() => {            this.setState({fin: true})        }, 10000);    }     render() {        const {fin} = this.state;        if(fin){            return (                <div className="modal show">        <div className="modal-dialog modal-dialog-centered" role="document">          <div className="modal-content">            <div className="modal-header">              <h5 className="modal-title" id="exampleModalLongTitle">Modal               title</h5>              <button type="button" name="test" className="close" onClick={this.handleClose} data-dismiss="modal"               aria-label="Close">              <span aria-hidden="true">&times;</span>              </button>            </div>            <div className="modal-body">              ...            </div>            <div className="modal-footer">              <button type="button" className="btn btn-secondary" data-                dismiss="modal">Close</button>              <button type="button" className="btn btn-primary">Save               changes</button>            </div>          </div>        </div>      </div>            )        } else {        return (              <div>                  Child counting...              </div>         )        }    }}export default Timer;
查看完整描述

1 回答

?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

您必須在子組件的 render() 上方添加一個用于處理關閉模型的函數。

handleClose()=>{
   this.setState({fin:false});
}


查看完整回答
反對 回復 2022-08-18
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號