学无先后,达者为师

网站首页 Vue 正文

vue生命周期beforeDestroy和destroyed调用方式_vue.js

作者:飞飞飞~元宝   更新时间: 2022-08-21 Vue

生命周期beforeDestroy和destroyed调用

情境一

离开当前路由,会直接调用;

当前路由不使用 缓存,离开当前路由会直接调用 beforeDestroy 和 beforeDestroy 销毁

情景二

离开当前路由,不会直接调用,需要程序控制调用;

当前路由使用 缓存,离开当前路由不会直接调用 beforeDestroy 和 beforeDestroy 销毁,需要使用路由钩子函数主动的调用

beforeRouteLeave(to, from, next) {
  this.$destroy();
  next();
}

beforeDestroy和destroyed生命周期函数的特点

beforeDestroy生命周期函数表示即将销毁,此时仍然可以使用子组件的实例、methods、watch

到了destroyed生命周期函数,此时已经被销毁,无法再使用子组件的实例,methods、watch

原文链接:https://blog.csdn.net/qq_42894952/article/details/108357386

栏目分类
最近更新