title: How can I mimic onbeforeunload in a Vue.js 2 application?
body: <p>I have a Vue component that is tracking when it is "dirty" (e.g. unsaved). I would like to warn the user before they browse away from the current form if they have unsaved data. In a typical web application you could use <code>onbeforeunload</code>. I've attempted to use it in mounted like this:</p>
  
  <pre><code>mounted: function(){
    window.onbeforeunload = function() {
      return self.form_dirty ? "If you leave this page you will lose your unsaved changes." : null;
    }
  }
  </code></pre>
  
  <p>However this doesn't work when using Vue Router. It will let you navigate down as many router links as you would like. As soon as you try to close the window or navigate to a <em>real</em> link, it will warn you.</p>
  
  <p>Is there a way to replicate <code>onbeforeunload</code> in a Vue application for normal links as well as router links?</p>