vue 生命周期

刺骨的言语ヽ痛彻心扉 2022-05-12 11:14 139阅读 0赞
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <script type="text/javascript" src="https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script>
  6. </head>
  7. <body>
  8. <div id="app">
  9. <p>{
  10. { message }}</p>
  11. </div>
  12. <script type="text/javascript">
  13. var app = new Vue({
  14. el: '#app',
  15. data: {
  16. message : "xuxiao is boy"
  17. },
  18. beforeCreate: function () {
  19. console.group('beforeCreate 创建前状态===============》');
  20. console.log("%c%s", "color:red" , "el : " + this.$el); //undefined
  21. console.log("%c%s", "color:red","data : " + this.$data); //undefined
  22. console.log("%c%s", "color:red","message: " + this.message)
  23. },
  24. created: function () {
  25. console.group('created 创建完毕状态===============》');
  26. console.log("%c%s", "color:red","el : " + this.$el); //undefined
  27. console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
  28. console.log("%c%s", "color:red","message: " + this.message); //已被初始化
  29. },
  30. beforeMount: function () {
  31. console.group('beforeMount 挂载前状态===============》');
  32. console.log("%c%s", "color:red","el : " + (this.$el)); //已被初始化
  33. console.log(this.$el);
  34. console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
  35. console.log("%c%s", "color:red","message: " + this.message); //已被初始化
  36. },
  37. mounted: function () {
  38. console.group('mounted 挂载结束状态===============》');
  39. console.log("%c%s", "color:red","el : " + this.$el); //已被初始化
  40. console.log(this.$el);
  41. console.log("%c%s", "color:red","data : " + this.$data); //已被初始化
  42. console.log("%c%s", "color:red","message: " + this.message); //已被初始化
  43. },
  44. beforeUpdate: function () {
  45. console.group('beforeUpdate 更新前状态===============》');
  46. console.log("%c%s", "color:red","el : " + this.$el);
  47. console.log(this.$el);
  48. console.log("%c%s", "color:red","data : " + this.$data);
  49. console.log("%c%s", "color:red","message: " + this.message);
  50. },
  51. updated: function () {
  52. console.group('updated 更新完成状态===============》');
  53. console.log("%c%s", "color:red","el : " + this.$el);
  54. console.log(this.$el);
  55. console.log("%c%s", "color:red","data : " + this.$data);
  56. console.log("%c%s", "color:red","message: " + this.message);
  57. },
  58. beforeDestroy: function () {
  59. console.group('beforeDestroy 销毁前状态===============》');
  60. console.log("%c%s", "color:red","el : " + this.$el);
  61. console.log(this.$el);
  62. console.log("%c%s", "color:red","data : " + this.$data);
  63. console.log("%c%s", "color:red","message: " + this.message);
  64. },
  65. destroyed: function () {
  66. console.group('destroyed 销毁完成状态===============》');
  67. console.log("%c%s", "color:red","el : " + this.$el);
  68. console.log(this.$el);
  69. console.log("%c%s", "color:red","data : " + this.$data);
  70. console.log("%c%s", "color:red","message: " + this.message)
  71. }
  72. })
  73. </script>
  74. </body>
  75. </html>

发表评论

表情:
评论列表 (有 0 条评论,139人围观)

还没有评论,来说两句吧...

相关阅读

    相关 vue生命周期

    vue官网讲解生命周期 传送门-[添加链接描述][Link 1] beforecreate() 在实例初始化之后,数据观测 (data observer) 和

    相关 vue生命周期

    vue生命周期的理解 vue生命周期是指vue实例对象从创建之初到销毁的过程。 vue的生命周期总共分为8个阶段:创建前/后,载入前/后,更新前/后,销毁前/后 vue生

    相关 vue 生命周期

    1/ beforeCreate() 在创建Vue对象之前 ; 用途动画加载 2/ created() 组件(Vue的实例化对象)创建好了,属性也绑定了,但是DOM还没生成;用