vue的声明周期
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="test">
    <button @click="destoryVm">destory vue</button>
    <p v-show="isShow">青木传奇</p>
</div>
<script src="../js/vue.js"></script>
<script>
    new Vue({
        el:'#test',
        data:{
            isShow:true
        },
        //1.初始化阶段
        beforeCreate(){
          console.log('beforeCreate')
        },
        created(){
            console.log('Create')
        },
        mounted(){ //初始化显示之后立即调用
            console.log('mounted')
            this.intervalId = setInterval(()=>{
                this.isShow=!this.isShow
            },1000)
        },
        //2.更新阶段
        beforeUpdate(){
            console.log('beforeUpdate')
        },
        updated(){
            console.log('updated')
        },
        beforeDestory(){//死亡之前调用(1次)
            //清楚定时器
            clearInterval(this.intervalId)
        },
        destory(){
        },
        methods:{
            destoryVm(){
                //干掉vm
                this.$destroy()
            }
        }
    })
</script>
</body>
</html>

本文来自博客园,作者:King-DA,转载请注明原文链接:https://www.cnblogs.com/qingmuchuanqi48/articles/15004551.html
                    
                
                
            
        
浙公网安备 33010602011771号