Recently I started working on a small open-source project side project with Vue, and I wanted to create yes/no dialog (basically a model) which will s

Why JavaScript dialogs (alert/prompt/confirm) are not widely used?

submited by
Style Pass
2021-06-15 18:30:05

Recently I started working on a small open-source project side project with Vue, and I wanted to create yes/no dialog (basically a model) which will show a notification with a confirm and cancel button. So users can confirm or cancel an event.

However, since I don’t want to reuse my code and repeat the same code, I created a separate Vue component called notification just to show a notification with a yes/no button.

Then I came across this problem, how am I going to handle the event? The notification will be triggered by different events, and upon confirmation it should run different events, depending on the parent event which fired it.

How am I going to track of the parent event which triggered the notification and child event that should run upon confirmation? By the way I also need to pass parameters to the child event as well. For example let’s look at changing the text inside a DOM element.

This is a very ugly approach, I have to set a state with parameters for the child event (the event that is triggered when confirmed), or else I have to pass the parameters to the notification and re-send it again to the child event.

Leave a Comment