VUE中computed 、created 、mounted的先后顺序说明

computed 、created 、mounted先后顺序

1.computed 、created 、mounted 的先后顺序

  • created => computed => mounted

2.父子组件生命周期执行顺序​

  • 页面初始化时: 父beforeCreate -> 父created -> 父beforeMount ->子beforeCreate -> 子created ->
  • 子beforeMount -> 子mounted-> 父mounted
  • 页面销毁时: 父beforeDestroy -> 子beforeDestroy ->子destroyed->父 destroyed
  • 销毁时也是子组件要先于父组件销毁

3.页面跳转的生命周期执行顺序

  • 旧页面跳转到新页面: 新页面created > 新beforeMount > 旧beforeDestroy > 旧:destroyed > 新mounted

4.computed 、watch、created 、mounted 的先后顺序

  • immediate 为false时: created => computed => mounted => watch
  • immediate 为true时: watch =>created=> computed => mounted

mounted和created在页面加载过程只执行一次,computed和watch是用来监听值发生变化的

VUE中的mounted和created在页面加载过程只执行一次,computed和watch是用来监听值发生变化的

今天在做项目的时候,发现重新打开页面,传给子组件的值,会被监听到,但是在打开页面之后,再做操作就会发现监听不到里面的值。后来把值的监听放到watch方法中,终于监听到了。

后来去官网进行查询,重新熟悉了一下VUE的生命周期

发现

VUE中的mounted和created在页面加载过程只执行一次,computed和watch是用来监听值发生变化的

长个记性

总结

作者:吃炸鸡的前端原文地址:https://blog.csdn.net/weixin_43239880/article/details/124478858

%s 个评论

要回复文章请先登录注册