14_声明周期函数.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./js/vue.js"></script>
  8. </head>
  9. <body>
  10. <div id="app">
  11. {{num}}
  12. <button @click="changeFun">change</button>
  13. </div>
  14. <script>
  15. let app = new Vue({
  16. el: '#app',
  17. data:{
  18. num:1
  19. },
  20. methods:{
  21. changeFun:function(){
  22. this.num++
  23. }
  24. },
  25. // 生命周期函数
  26. // beforeCreate 表示vue实例刚被创建,还没有初始化数据
  27. beforeCreate:function(){
  28. console.log('beforeCreate')
  29. },
  30. // created 表示vue实例已经创建完成,数据已经初始化完成
  31. created:function(){
  32. console.log('created')
  33. },
  34. // beforeMount 表示vue实例已经创建完成,但是还没有挂载到页面上
  35. beforeMount:function() {
  36. console.log('beforeMount')
  37. },
  38. // mounted 表示vue实例已经挂载到页面上
  39. mounted:function() {
  40. console.log('mounted')
  41. },
  42. // beforeUpdate 表示vue实例的数据已经更新完成,但是页面还没有更新
  43. beforeUpdate:function() {
  44. console.log('beforeUpdate');
  45. },
  46. // updated 表示vue实例的数据已经更新完成,页面也更新完成
  47. updated:function(){
  48. console.log('updated');
  49. },
  50. // beforeDestroy 表示vue实例即将被销毁
  51. beforeDestroy:function(){
  52. console.log('beforeDestroy');
  53. },
  54. // destroyed 表示vue实例已经被销毁
  55. destroyed:function(){
  56. console.log('destroyed');
  57. }
  58. })
  59. </script>
  60. </body>
  61. </html>