Vue 2 lifecycle - how to stop beforeDestroy?

Can I add something beforeDestroyto prevent component destruction?

Or is there a way to prevent component destruction?

My thing is that when I change the spa page to vue-route, I first use the browse route, but I found that this does not work because the component simply destroys.

+4
source share
2 answers

You can use vue-route navigation-guards , so if you call next(false)inside the hook, navigation will be aborted.

router.afterEach((to, from) => {
  if(your condition){
    next(false) //this will abort route navigation
  }
})
+3
source

As belmin bedak commented , you can usekeep-alive

  • keep-alive, : activated deactivated destroyed

  • keep-alive -

  • include exclude atteibutes keep-alive , shookb, .

  • , , , vm.$destroy()

, console.log ,

+1

Source: https://habr.com/ru/post/1674962/


All Articles