react 中 Modal 多次使用且帶參數不同實現


一.舉例:對於 echatrs 的柱子分別需要彈窗 帶參數 觸發彈窗出現事件 showModalhref
 1   myChart.on('click', (params) => {  2 switch (params.seriesIndex) {  3 // echarts 雙柱1  4 case 0: this.showModalhref('kjxy', industryBar_list.list, params);  5 break;  6 // echarts 雙柱2  7 case 1: this.showModalhref('cpxy', industryBar_list.list, params);  8 break;  9 default: break; 10  } 11 });

 

二、modal  

   state = {   modalShowHref: { visibleHref: false, type: '', data1: [], data2: {}, },  } <Modal visible={this.state.modalShowHref.visibleHref}  onOk={this.okModalhref} onCancel={this.hideModalhref} okText="確認" cancelText="取消" width={278} className={styles.hrefModal} > <p>確定跳轉嗎?</p> </Modal>

 

  三、點擊onOk時

okModalhref = () => { const { modalShowHref } = this.state; const { type } = modalShowHref; const { data1 } = modalShowHref; const { data2 } = modalShowHref; if (type === 'kjxy') { // 框架協議 (arr, params) const obj = data1.find(t => t.name === data2.name); const { corpCstTps } = obj; this.props.dispatch(routerRedux.push({ pathname: '/QYGL/kjxy/query', state: { corpCstTps, }, })); } else if (type === 'cpxy') { // 產品協議 (arr, params) const obj = data1.find(t => t.name === data2.name); const { corpCstTps } = obj; this.props.dispatch(routerRedux.push({ pathname: '/QYGL/cpxy/searchList', state: { corpCstTps, }, })); } };

四、點擊onCancel時

/////彈窗中 取消事件 hideModalhref = () => { this.setState({ modalShowHref: { visibleHref: false, type: '', data1: [], data2: {}, }, }); };

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM