Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用reactjs引导创建模态_Reactjs_Bootstrap Modal - Fatal编程技术网

使用reactjs引导创建模态

使用reactjs引导创建模态,reactjs,bootstrap-modal,Reactjs,Bootstrap Modal,我有点绝望了。我想使用引导在reactjs中创建一个模态对话框。我已经安装了带有npm的模块,并将其导入到我的代码中。我尝试了一个简单的例子: import React from 'react'; import {Modal, Button } from 'react-bootstrap'; class Config extends React.Component { constructor(){ super(); this.state = { sho

我有点绝望了。我想使用引导在reactjs中创建一个模态对话框。我已经安装了带有npm的模块,并将其导入到我的代码中。我尝试了一个简单的例子:

import React from 'react';
import {Modal, Button } from 'react-bootstrap';


class Config extends React.Component {


constructor(){
    super();

    this.state = {

        show: false
    }
    this.handleHide = this.handleHide.bind(this);

}


handleHide() {
    this.setState({ show: false });
}

render(){


    return ( <div>
            <Button
                bsStyle="primary"
                bsSize="large"
                onClick={() => this.setState({ show: true })}
            >
                Launch modal
            </Button>

            <Modal show={this.state.show} onHide={this.handleHide}>
                <Modal.Header >
                   Header
                </Modal.Header>
                <Modal.Body>
                    Text
                </Modal.Body>
                <Modal.Footer>
                    <Button onClick={this.handleHide}>Close</Button>
                </Modal.Footer>
            </Modal>
    </div>)
}

}

export default Config;
从“React”导入React;
从“react bootstrap”导入{Modal,Button};
类配置扩展了React.Component{
构造函数(){
超级();
此.state={
节目:假
}
this.handleHide=this.handleHide.bind(this);
}
handleHide(){
this.setState({show:false});
}
render(){
报税表(
this.setState({show:true})}
>
发射模态
标题
正文
接近
)
}
}
导出默认配置;
我没有得到任何错误,但如果我点击按钮,我也看不到任何东西。我用Chrome开发者工具查看了所有元素,我可以看到其中的模式,这让人困惑。
有人知道什么是错的吗?

这对我来说很有效,几乎和你的例子一样。但是,我没有单独使用一个函数来处理状态,而是对
handleClose
HandleShow
使用了两个函数

从“React”导入React;
从'react router dom'导入{Link};
从“react bootstrap”导入{Modal,Button};
类头扩展了React.Component{
建造师(道具){
超级(道具);
this.handleClose=this.handleClose.bind(this);
this.handleShow=this.handleShow.bind(this);
此.state={
节目:假
}
}
handleClose(){
这是我的国家({
节目:假
});
}
handleShow(){
这是我的国家({
秀:真的
});
}
render(){
//console.log(this.state);
返回(
  • 接触
  • 登录
模态头 模态体 ) } }
导出默认标题嗯。。前几天我遇到了同样的问题。然而,我所做的是为模态函数提供两个不同的函数。一个用于展示,一个用于展示,一个用于展示,它对我起了作用。如果你愿意,我可以给你看我的例子。@Curious13我试过,但仍然不起作用。如果您能显示您的代码,我将不胜感激,也许您做了一些不同的尝试,用此替换handleHide函数。
this.setState({
show:!this.state.show
`})`不要为我工作,但是谢谢。我想试试别的东西,好吗?那很有趣。我现在正在使用这个代码示例,它对我来说很好。对不起,我帮不上忙。