Currently, I have developed an alert component that is utilized in my project. For example, it can be called using
<AlertComponent message="message" />
.
In my main App.vue file, I have a method that handles incoming messages and I would like to dynamically create an AlertComponent and add it to the DOM when a new message arrives. This is necessary because the number of messages received can vary, and each component should only display for 5 seconds before removing itself from view.
I am unsure of how to add a component dynamically within the App.vue file itself. My initial idea was to have a div in the template where I could simply "addChild" or something similar.
What is the recommended approach in Vue.js for achieving this functionality? I am hesitant to use a v-for
loop on the alert component as managing an array of components may lead to issues with data binding and redrawing components that have already been displayed on screen but not yet destroyed.