vue的生命周期函數(shù)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
    <div id="app">
    </div>
    <script>
        // 生命周期函數(shù)就是 Vue實例在某一個時間點自動執(zhí)行的函數(shù)
        var vm = new Vue({
            el : "#app",
            template : "<div>{{message}}</div>",
            data : {
                message : "hello world"
            },
            // vue實例基礎初始化之后,就會觸發(fā)
            beforeCreate : function(){
                console.log("beforeCreate");
            },
            created : function(){
                console.log("created");
            },
            // 如果沒有template模板,就會將el內(nèi)的當成模板
            // 如果有template,就會用template里的東西
            // beforeMount:當和模板結(jié)合,在渲染頁面之前的一瞬間,執(zhí)行beforeMount函數(shù)(還沒有渲染到頁面上————用模板的情況下)
            beforeMount : function(){
                console.log(this.$el);
                console.log("beforeMount");
            },
            // 這時候hello World就會渲染在頁面上了
            // mounted就會自動執(zhí)行(已經(jīng)渲染了)
            mounted : function(){
                console.log(this.$el);                
                console.log("mounted");
            },
            // 實例還沒有銷毀,在銷毀的前一刻
            // 銷毀實例:vm.$destroy()
            beforeDestroy : function(){
                console.log("beforeDestory");
            },
            // 實例被銷毀了
            destroyed : function(){
                console.log("destoryed");
            },
            // 數(shù)據(jù)發(fā)生改變,還沒渲染之前
            beforeUpdate : function(){
                console.log("beforeUpdate");
            },
            // 數(shù)據(jù)改變,渲染之后
            updated : function(){
                console.log("updated");
            }
            
        })
    </script>
</body>
</html>
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容