Do not allow exiting the form screen without saving

Viewed 172

how can I issue an alert to the user when he wants to leave the form with input filled without saving?

I have already tried to implement something inside beforeDestroy, but I can not abort the output

Can I abort the screen output inside the:

router.beforeEach((to, from, next) => {

  if(!store.getters.getStatusEdit){
    next(false);
  }

})

But it did not work, because the vuex that runs inside beforeDestroy runs after the route.

Anyone have any suggestions?

1 Answers

inside component using:

beforeRouteLeave (to, from, next) {

        if(this.dados.name){

            if(confirm('confirm?')){

                next()

            }else{ next(false) };

        }else{
            next()
        }
    },
Related