简体   繁体   中英

Launch Bootstrap modal on page load in a React based site.

I need to load a page and as soon as it loads pop up a modal with some info for the user. I have tried this using the standard:

$(window).on('load',function(){
    $('#myModal').modal('show');
});

However, that does nothing. I think it doesn't work because of the way React loads and uses a virtual DOM. (I could be wrong on this)

But is there a way to launch a bootstrap modal on page load in React?

在您尝试安装的组件的生命周期方法中调用模态(例如, componentDidMount()在已安装时进行模态调用)。

I don't know if I understand correctly but If you are using Reactjs then I think you should use a library that implement bootstrap in a react way, maybe React bootstrap or Reactstrap

Import the library and use the Modal component the library gives you, and just pass the right property to show the Modal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM