美文网首页
react小技巧-多个弹层的调用

react小技巧-多个弹层的调用

作者: 小太阳可可 | 来源:发表于2019-08-13 16:33 被阅读0次
1.gif
import React from "react"
import {Card,Button,Modal} from "antd";
import "./ui.less";

export default class Modals extends React.Component{
    state = {
        showModal1:false,
        showModal2:false,
        showModal3:false,
        showModal4:false,
    }
    showModal = (type)=>{
        this.setState({
            [type]:true             // [type]  重点在这里哦!!!
        })
    }
    handleConfirm = (type)=>{
        Modal[type]({               // [type]  重点在这里哦!!!
            title:"信息确认框",
            content:"自出洞来无敌手,得饶人处且饶人!",
            onOk(){
                console.log('ok')
            }
        })
    }
    render(){
        return (
            <div>
                <Card title="基础模态框">
                    <Button type="primary" onClick={()=>this.showModal('showModal1')}>Open</Button>
                    <Button type="primary" onClick={()=>this.showModal('showModal2')}>自定义页脚</Button>
                    <Button type="primary" onClick={()=>this.showModal('showModal3')}>顶部20px弹框</Button>
                    <Button type="primary" onClick={()=>this.showModal('showModal4')}>水平垂直</Button>
                </Card>
                <Card title="信息确认框">
                    <Button type="primary" onClick={()=>this.handleConfirm('confirm')}>Confirm</Button>
                    <Button type="primary" onClick={()=>this.handleConfirm('info')}>Info</Button>
                    <Button type="primary" onClick={()=>this.handleConfirm('success')}>Success</Button>
                    <Button type="primary" onClick={()=>this.handleConfirm('error')}>Error</Button>
                </Card>
                <Modal
                    title="Open"
                    visible={this.state.showModal1}
                    onOk={()=>
                        this.setState({
                            showModal1:false
                        })
                    }
                    onCancel={()=>
                        this.setState({
                            showModal1:false
                        })
                    }
                >
                    <p>自出洞来无敌手,得饶人处且饶人!</p>
                </Modal>
                <Modal
                    title="自定义页脚"
                    visible={this.state.showModal2}
                    onOk={()=>
                        this.setState({
                            showModal2:false
                        })
                    }
                    onCancel={()=>
                        this.setState({
                            showModal2:false
                        })
                    }
                    cancelText = "取消"
                    okText = "确定"
                >
                    <p>自出洞来无敌手,得饶人处且饶人!</p>
                </Modal>
                <Modal
                    title="顶部20px弹框"
                    visible={this.state.showModal3}
                    style={{top:20}}
                    onOk={()=>
                        this.setState({
                            showModal3:false
                        })
                    }
                    onCancel={()=>
                        this.setState({
                            showModal3:false
                        })
                    }
                >
                    <p>自出洞来无敌手,得饶人处且饶人!</p>
                </Modal>
                <Modal
                    title="水平垂直"
                    visible={this.state.showModal4}
                    wrapClassName="vertical-center-modal"
                    onOk={()=>
                        this.setState({
                            showModal4:false
                        })
                    }
                    onCancel={()=>
                        this.setState({
                            showModal4:false
                        })
                    }
                >
                    <p>自出洞来无敌手,得饶人处且饶人!</p>
                </Modal>
            </div>
        )
    }
}

相关文章

  • react小技巧-多个弹层的调用

  • React Native-弹框存在TextInput,输入框有焦

    Bug情况描述:React Native项目中,点击按钮A出现弹框浮层,弹框中需要TextInput输入数字,键盘...

  • react的旧的生命周期

    注意:State 的更新可能是异步的,React 可能会把多个 setState() 调用合并成一个调用

  • dubbo简单使用

    首先来看看Maven分层分模块架构 表现层调用服务层关系紊乱,一个服务层被多个表现层调用那是不是又可以抽出来?如果...

  • 2018-12-10

    1.状态更新可能是异步的 React 可以将多个setState()调用合并成一个调用来提高性能。 因为this....

  • NDN开发之双向沟通

    概念:双向沟通的意思是java调用c++层,c++层同样可以调用java,同时要解决多对多问题,即多个java对象...

  • React不熟悉地方的笔记

    1. 状态更新可能是异步的 React 可以将多个setState() 调用合并成一个调用来提高性能。因为 thi...

  • React-Native 浮层弹框

    源码地址:https://github.com/chjwrr/RN-floatLayer具体使用请看 README.md

  • Block 的多种使用场景

    在对于使用iOS系统的弹框提示UIAlertController框架的时候,发现在多个地方调用的时候,会出现很多重...

  • react的传值和周期

    react传值 1.父传子,直接在model层调用service层,然后依次传下来, 2.无状态组件传有状态组件 ...

网友评论

      本文标题:react小技巧-多个弹层的调用

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