Reputation: 23
I am navigating to a route which have a component: Diagnostic
The route looks like
localhost:8080/sav/:id/diagnostic
Whenever the route is visited I send a post request to the backend in order to lock the object which match the :id
I want to send another post request (execute a function) whenever the user navigate somewhere else in order to unlock the object
I used Vue JS lifecycle hooks with BeforeUnmount, unmounted, destroyed :
unmounted() {
this.unlockObject()
}
I also tried to use watch to execute the function on route changes.
But none worked
I am not sure if the component is even unmounted when I navigate somewhere else in my app.
How to call my function when user navigate somewhere else?
I am using vue2 with vue router
Upvotes: 0
Views: 1678
Reputation: 23
Answering my own question
beforeDestroy () {
this.unlockObject()
}
did the trick...
The function name is case sensitive
Upvotes: 2