鍍金池/ 問答/HTML  Office/ React 組件設(shè)計(jì)問題

React 組件設(shè)計(jì)問題

為什么 React Modal 組件在設(shè)計(jì)時(shí),點(diǎn)擊關(guān)閉 Modal 按鈕不在組件內(nèi)部直接處理關(guān)閉邏輯,而是通過事件告知 外部組件 去關(guān)閉 Modal,而 Vue element-ui 中則可以在組件內(nèi)部自行處理關(guān)閉 Dialog 邏輯

https://design.alipay.com/dev...
http://element.eleme.io/#/zh-...

回答
編輯回答
有你在

首先來說 兩者的效果肯定是一樣的毋庸置疑
react本身設(shè)計(jì)的時(shí)候就認(rèn)為--組件的狀態(tài),是由組件的屬性來決定的
那么antd-design中這個(gè)modal也是一樣的。設(shè)計(jì)的時(shí)候就希望 這個(gè)組件是由某個(gè)外部給他的屬性來控制,所以自然就這么設(shè)計(jì)啦

2017年6月13日 23:43
編輯回答
涼汐
import { Modal, Button } from 'antd';

const confirm = Modal.confirm;

function showConfirm() {
  confirm({
    title: 'Do you want to delete these items?',
    content: 'When clicked the OK button, this dialog will be closed after 1 second',
    onOk() {
      return new Promise((resolve, reject) => {
        setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
      }).catch(() => console.log('Oops errors!'));
    },
    onCancel() {},
  });
}

ReactDOM.render(
  <Button onClick={showConfirm}>
    Confirm
  </Button>,
  mountNode);

看清楚好吧
也是有的

2017年10月18日 04:33