vue.js Vue2的生命周期(钩子函数)

vue-lifecycle.png
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <script type="text/javascript" src="../assets/js/vue.js"></script>
 <title>构造器的声明周期</title>
</head>
<body>
 <h1>构造器的声明周期</h1>
 <hr>
 <div id="app">
     {{message}}
     <p><button @click="jia">加分</button></p>
 </div>
     <button onclick="app.$destroy()">销毁</button>

 <script type="text/javascript">
     var app=new Vue({
         el:'#app',
         data:{
             message:1
         },
         methods:{
             jia:function(){
                 this.message ++;
             }
         },
         beforeCreate:function(){
             console.log('1-beforeCreate 初始化之后');
         },
         created:function(){
             console.log('2-created 创建完成');
         },
         beforeMount:function(){
             console.log('3-beforeMount 挂载之前');
         },
         mounted:function(){
             console.log('4-mounted 被创建');
         },
         beforeUpdate:function(){
             console.log('5-beforeUpdate 数据更新前');
         },
         updated:function(){
             console.log('6-updated 被更新后');
         },
         activated:function(){
             console.log('7 keep-alive组件激活时调用。该钩子在服务器端渲染期间不被调用 ');
         },
         deactivated:function(){
             console.log('8 keep-alive组件停用时调用。该钩子在服务端渲染期间不被调用。');
         },
         beforeDestroy:function(){
             console.log('9-beforeDestroy 销毁之前');
         },
         destroyed:function(){
             console.log('10-destroyed 销毁之后')
         }

     })
 </script>
</body>
</html>


参考文章
https://blog.csdn.net/qq_24147051/article/details/81167093

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容