Vue全局API-生命周期

Vue 生命周期

<body>
    <h1>Vue 生命周期<h1>
    <hr>
    <div id="app">
        {{count}}
        <p><button @click="add">add</button></p>
    </div>
    <button onclick="app.$destroy()">销毁</button>

    <script type="text/javascript">
    
        var app = new Vue({
            el:'#app',
            data:{
                count:1,
            },
            methods:{
                add:function(){
                    this.count++;
                }
            },
            
            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-activated");
            },
            deactivated:function(){
                console.log("8-deactivated");
            },
            beforeDestroy:function(){
                console.log("9-beforeDestroy 销毁之前");
            },
            destroyed:function(){
                console.log("10-destroyed 销毁之后");
            },
        })
    </script>
</body>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 使用Vue在日常开发中会频繁接触和使用生命周期,在官方文档中是这么解释生命周期的: 每个 Vue 实例在被创...
    心_c2a2阅读 6,729评论 1 8
  • 前言 记录平时学到的知识,标题写的大气一点,也算是给自己一点鼓励,希望在技术这条路可以远走越远,路越走越宽~ 文中...
    徐国军_plus阅读 5,579评论 3 28
  • PS:转载请注明出处作者: TigerChain地址: https://www.jianshu.com/p/0d5...
    TigerChain阅读 22,893评论 1 80
  • 伟大的催眠师米尔顿.艾瑞克森是这么说的:“症状是渡过生命周期某一阶段时出现困难的信号。为了人们进一步发展,这里有些...
    郭秀艳阅读 2,507评论 0 2
  • 道慈早安分享! 一个人的涵养,不在心平气和时,而在心浮气燥时;一个人的理性,不在风平浪静时,而在众声喧哗时;一个人...
    道慈阅读 1,768评论 0 1