'Nuxtlj when user refresh,back,close show popup if click refresh or close fire method

I want to my Nuxtjs application when user click refresh or back or close window to show pop up 'Changes made you may not save' and if click refresh or close to the pop up run a method.

If click cancel i want nothing happens!

My point of view is this function to add an event Listener in mounted method and if user click some of this to run a method only if user Refresh or close tab or close window or back button!

window.addEventListener('beforeunload', this.reset)

I want to know how can i realize that user click refresh or close in the pop up to run a method



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source