2

I have several forms and input fields that I use in my Customize.vue file. I have to detect any unsaved changes and trigger a notification.

methods: {
    alertChange() {
        this.$notify.make('You have unsaved changes!', 'warning');
    }
}   
Bargain23
  • 1,863
  • 3
  • 29
  • 50
  • 1
    Are you using vue router? – Shubham Patel Jul 25 '17 at 06:38
  • Hi. I just learned about vue-router a while ago. I tried using `beforeRouteLeave` that contains `alert('Unsaved changes')` but it doesn't get triggered. – Bargain23 Jul 25 '17 at 06:40
  • Can you share demo code if possible? – Shubham Patel Jul 25 '17 at 06:42
  • 1
    I literally just added this after `methods`, `beforeRouteLeave (to, from, next) { alert('Unsaved changes'); }` – Bargain23 Jul 25 '17 at 06:44
  • @Bargain23 wouldn't your solution alert the user even if there are no changes to save? You should implement dirty flags to keep track of changes, take a look [here](https://stackoverflow.com/a/7317311/583895) (although it's vanilla javascript, the concepts for vue.js are similar) – andresgottlieb Jul 25 '17 at 21:06

0 Answers0