zoukankan      html  css  js  c++  java
  • React之React.cloneElement

    如果把一个页面分为多个组件组成的话(组件多层嵌套),

    想要在PanelCalendar之间传值就不能用以往的props属性了。

    解决方法:

    Panel.js

            return (
                <Form.Root className={`bg-white ${type === 'reading' ? 'reading-min-height' : ''}`}>
                    <div className="panel-title">
                        <h4 className="webfont">
                            <span className={"topTitle"}>{this.props.title}</span>
                        </h4>
                        {type === "reading" ? <a className="rightFont" onClick={() => this.onOpenTabs()}>更多></a> : ""}
    
                        {workDay ?
                            <Popover placement="bottom" content={
                                <div style={{display: 'flex', flexDirection: 'column', justifyContent: 'center'}}>
                                    <Button type="primary" onClick={() => this.showMadel('2')}
                                            style={{marginBottom: 10}}>便笺</Button>
                                    <Button type="primary" onClick={() => this.showMadel('1')}>日程</Button>
                                </div>
                            }
                                     title="">
                                <a className="more">
                                    <i className="iconfont iconxinzengricheng mr-1"/>新建
                                </a>
                            </Popover>
                            : ""}
                        <Modal
                            width={window.innerWidth * 0.7}
                            style={{
                                top: 30
                            }}
                            title=""
                            visible={visible}
                            onOk={this.handleOk}
                            // confirmLoading={confirmLoading}
                            okText='ok'
                            footer={null}
                            onCancel={this.handleCancel}
                        >
                            <div id="pannelDialog">
                                {CreateTitle(title)}
                                {createInput()}
                                <div>
    
                                    <div className="input-group mt-3 mb-3">
                                        <div className="input-group-prepend">
                                            <div>{types === 'view' ? attachments.length > 0 ? '查看图片:' : '' : '上传图片:'}</div>
                                        </div>
                                    </div>
    
                                    {types === 'view' ? attachments.length > 0 ?
                                        <ImageUploader width={80} height={80} attachments={attachments} types={types}
                                                       pushAttachments={this.pushAttachments}
                                                       removeAttachments={this.removeAttachments}/> : '' :
                                        <ImageUploader width={80} height={80} attachments={attachments} types={types}
                                                       pushAttachments={this.pushAttachments}
                                                       removeAttachments={this.removeAttachments}/>}
                                </div>
                                {CreateButton(this.submit, this.hideMadel, types)}
                            </div>
                        </Modal>
                    </div>
                    {this.props.children && React.cloneElement(this.props.children, {
                        handleClick: this.postValue,
                        onRef: this.onRef,
                    })}
                </Form.Root>
            );

    使用React.cloneElement(this.props)来渲染子元素,使用第二个参数props来传值

  • 相关阅读:
    比较全的屏幕信息
    使用div实现progress进度条
    选项卡效果的菜单栏
    javascript写的轮播图
    centos6.5 命令行配置无线上网
    CentOS 6.5 BCM43142 80211无线网卡驱动安装
    [数据库] windows server 2003下mysql出现10048错误的解决办法 Can't connect to MySQL server on '127.0.0.1' (10048)
    桥接模式-多台虚拟机配置(重要)
    VMware虚拟机中如何配置静态IP
    MySQL5.7 mysql.user创建用户
  • 原文地址:https://www.cnblogs.com/it-Ren/p/13889336.html
Copyright © 2011-2022 走看看