zoukankan      html  css  js  c++  java
  • (三)Vue生命周期

    1. vue对象的生命周期

      1). 初始化显示

        * beforeCreate()

        * created()

        * beforeMount()

        * mounted()

      2). 更新状态

        * beforeUpdate()

        * updated()

      3). 销毁vue实例: vm.$destory()

        * beforeDestory()

        * destoryed()

    2. 常用的生命周期方法

      created()/mounted(): 发送ajax请求, 启动定时器等异步任务

      beforeDestory(): 做收尾工作, 如: 清除定时器

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>生命周期</title>
    </head>
    <body>
    <!--
    1. vue对象的生命周期
      1). 初始化显示
        * beforeCreate()
        * created()
        * beforeMount()
        * mounted()
      2). 更新状态
        * beforeUpdate()
        * updated()
      3). 销毁vue实例: vm.$destory()
        * beforeDestory()
        * destoryed()
    2. 常用的生命周期方法
      created()/mounted(): 发送ajax请求, 启动定时器等异步任务
      beforeDestory(): 做收尾工作, 如: 清除定时器
    -->
    
    <div id="test">
        <button @click="destroyVue">destory vue</button>
        <p v-if="isShow">123456</p>
    </div>
    
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript">
        new Vue({
            el: '#test',
            data: {
                isShow: true
            },
            mounted(){
                //页面渲染的时候,
                this.IntervalId = setInterval(()=>{
                    console.log("-----");
                    this.isShow = !this.isShow;
                },500)
            },
            beforeDestroy(){
                    //销毁之前清除定时器
                clearInterval(this.IntervalId)
            },
            methods:{
                destroyVue(){
                    this.$destroy();//销毁VM对象
                }
            }
    
        })
    
    
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    C语言中for循环的使用
    详解C语言的main函数
    计算机语言的发展(the history of computer's language)
    hdu 1001
    hoj 1002
    hdu 1000
    POJ 1000(水题)
    hoj 1001
    code hunt题解(1)
    《C和指针》学习笔记(3)
  • 原文地址:https://www.cnblogs.com/love-life-insist/p/10077106.html
Copyright © 2011-2022 走看看