onbeforeunload event confirmation

I am using Laravel and Vue js. I am creating a wizard which has three steps. And I am using onbeforeunload event for showing if a person tries to do anything unwanted. Now the thing is this event will show a message saying Leave or Stay. When the person clicks on Leave button I want to perform a specific action and when the person clicks on Stay button I don’t want that action to be executed. Right now it is running every time. How can I update that?

What I have tried:

window.onbeforeunload = function(e){
                //action here
                e.returnValue =  "Changes may not be saved";


In case anyone else is wondering about it.. you can do this by calling beforeunload event and onbeforeunload simultaneously. onbeforeunload will give the warning and beforeunload will perform your action.