gpt4 book ai didi

reactjs - 模态不会出现在 react 中

转载 作者:行者123 更新时间:2023-12-03 14:25:35 25 4
gpt4 key购买 nike

我正在使用react-bootstrap,并且我在组件函数中有一个模态,如下所示:

// stateless function component
function ServiceModal(props) {
return (
<Modal>
<Modal.Dialog>
<Modal.Header>
<Modal.Title>{props.item.name}</Modal.Title>
</Modal.Header>

<Modal.Body>
<p>{props.item.id}</p>
<p>{props.item.name}</p>
<p>{props.item.description}</p>
</Modal.Body>

<Modal.Footer>
<Button variant="secondary">Close</Button>
</Modal.Footer>
</Modal.Dialog>
</Modal>
);
}

该模式不会出现。内容不显示,甚至覆盖也不显示。这是我如何调用它来渲染它:

class Service extends Component {

renderServiceModal(service) {
return (
<ServiceModal
item={service}
/>
);
}

render() {
return (
<div className="container content">
<div className="row">
<div className="col-6">
<form>
<div className="form-group">
<label htmlFor="nom">Name</label>
<input name="name" ref="name" type="text" className="form-control" id="name" placeholder="Name"
onChange={(value) => this.onChange(value)} />
</div>
<div className="row">
<div className="col-sm-3">
<button onClick={this.postService.bind(this)} type="submit" className="btn btn-primary btn-block">Add</button>
</div>
</div>
</form>
</div>
<div className="col-6">
<ul className="list-group">
{this.state.services.map(service =>
<li onClick={() => { this.readOneService(service.id) }} className="list-group-item" key={service.id}>{service.nom}
<div className="btn-group btn-group-sm float-right" role="group">
<button type="button" className="btn btn-primary"
onClick={() => this.updateService(service.id)}>Update
</button>
<button type="button" className="btn btn-danger"
onClick={() => this.deleteService(service.id)}>Delete
</button>
</div>
</li>
)}
</ul>
</div>
</div>
</div>
);
}

没有任何显示...有什么帮助吗?

编辑:在我的主组件中使用渲染内的代码更新了问题

最佳答案

默认情况下,模式是隐藏的:https://react-bootstrap.github.io/components/modal/#modals-props

您需要设置show属性为 true:( <Modal show={true}> )

完整代码

// stateless function component
function ServiceModal(props) {
return (
<Modal show={true}>
<Modal.Dialog>
<Modal.Header>
<Modal.Title>{props.item.name}</Modal.Title>
</Modal.Header>

<Modal.Body>
<p>{props.item.id}</p>
<p>{props.item.name}</p>
<p>{props.item.description}</p>
</Modal.Body>

<Modal.Footer>
<Button variant="secondary">Close</Button>
</Modal.Footer>
</Modal.Dialog>
</Modal>
);
}

关于reactjs - 模态不会出现在 react 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54642790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com