15_生命周期.html 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="app">
  11. {{count}}
  12. <button @click="add()">+1</button>
  13. <button @click="des()">销毁</button>
  14. </div>
  15. <script src="./vue.js"></script>
  16. <script>
  17. var app = new Vue({
  18. el: '#app',
  19. data: {
  20. count: 1
  21. },
  22. methods:{
  23. add(){
  24. this.count ++
  25. },
  26. des(){
  27. this.$destroy()
  28. }
  29. },
  30. //组件实例刚刚创建之前 属性计算之前
  31. beforeCreate() {
  32. console.log('beforeCreate', this.$data, this.$el)
  33. },
  34. //组件实例刚刚创建完成 属性绑定 dom未生成 el不存在
  35. created() {
  36. console.log('created',this.$data,this.$el)
  37. },
  38. //挂载之前
  39. beforeMount(){
  40. console.log('beforeMount',this.$data,this.$el)
  41. },
  42. //挂载之后
  43. mounted(){
  44. console.log('mounted',this.$data,this.$el)
  45. },
  46. //更新之前
  47. beforeUpdate(){
  48. console.log('beforeUpdate',this.$data,this.$el)
  49. },
  50. //更新之后
  51. updated(){
  52. console.log('updated',this.$data,this.$el)
  53. },
  54. //销毁之前
  55. beforeDestroy(){
  56. console.log('beforeDestroy',this.$data,this.$el)
  57. },
  58. destroyed(){
  59. console.log('destroyed',this.$data,this.$el)
  60. }
  61. })
  62. </script>
  63. </body>
  64. </html>