具有反应成分。需要在页面加载时打开引导程序模式。尝试使用jQuery和简单的javascript,但没有成功。
反应成分:
import React, { Component } from 'react'
import $ from 'jquery'
class Login extends Component {
componentDidMount() {
// here I want to open modal
}
render() {
return (
<div className="modal fade WelcomeModal" id="WelcomeModal" tabIndex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered" role="document">
<div className="modal-content">
<div className="modal-header">
<div className="camera-box">
<img alt="" src="/img/yellow-logo.svg"/>
<h5 className="modal-title" id="exampleModalLabel">Welcome to the Cozy App!</h5>
</div>
</div>
<div className="modal-body">
<p className="text-center">On the following screens weʼll ask you to register the Cozys in your home & adjust your temperature settings. Youʼll need the following information:</p>
</div>
</div>
</div>
</div>
)
}
}
答案 0 :(得分:2)
看看这个codepen,它显示了如何将Bootstrap类与React结合起来而无需jQuery
toggleModal = () => this.setState({
showLogin: !this.state.showLogin
})
答案 1 :(得分:1)
答案 2 :(得分:1)
首先,请勿以反应方式使用JQUERY。 您只需要为显示或隐藏模式设置状态。就是这样。
<div onClick={this.setState({showModal: true})}
答案 3 :(得分:0)
在公共文件夹index.html中包含Js CDN https://getbootstrap.com/docs/4.0/getting-started/introduction/
然后按常规调用引导程序模式, https://getbootstrap.com/docs/4.0/components/modal/