美文网首页
antd 组件使用示例

antd 组件使用示例

作者: 第2世界 | 来源:发表于2020-01-08 13:22 被阅读0次
    import { Select, Icon, Divider } from 'antd';
    
    const { Option } = Select;
    
    let index = 0;
    
    class App extends React.Component {
      state = {
        items: ['jack', 'lucy'],
      };
    
      addItem = () => {
        console.log('addItem');
        const { items } = this.state;
        this.setState({
          items: [...items, `New item ${index++}`],
        });
      };
    
      render() {
        const { items } = this.state;
        return (
          <Select
            style={{ width: 240 }}
            placeholder="custom dropdown render"
            dropdownRender={menu => (
              <div>
                {menu}
                <Divider style={{ margin: '4px 0' }} />
                <div
                  style={{ padding: '4px 8px', cursor: 'pointer' }}
                  onMouseDown={e => e.preventDefault()}
                  onClick={this.addItem}
                >
                  <Icon type="plus" /> Add item
                </div>
              </div>
            )}
          >
            {items.map(item => (
              <Option key={item}>{item}</Option>
            ))}
          </Select>
        );
      }
    }
    
    ReactDOM.render(<App />, mountNode);
    

    相关文章

      网友评论

          本文标题:antd 组件使用示例

          本文链接:https://www.haomeiwen.com/subject/mffsactx.html