Vue技术17.1引出生命周期

<!DOCTYPE html>
<html>
    <head>
        <mata charset="UTF-8" />
        <title>引出生命周期</title>
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!--
            生命周期:
                1.又名:生命周期回调函数、生命周期函数、生命周期钩子
                2.是什么:Vue在关键时刻帮我们调用的一些特殊名称的函数
                3.生命周期函数的名字不可更改,但函数的具体内容是程序员根据需求编写的
                4.生命周期函数中的this指向是vm或组件实例对象
         -->
        <!-- 准备好一个容器 -->
        <div id="root">
            <h2 :style="{opacity}">欢迎学习Vue</h2>
        </div>
    </body>

    <script type="text/javascript">
        Vue.config.productionTip = false

        new Vue({
    
    
            el:'#root',
            data:{
    
    
                opacity:1
            },
            mounted(){
    
    
                setInterval(() => {
    
    
                    this.opacity -= 0.01
                    if(this.opacity <= 0) this.opacity = 1
                },30)
            }
        })
    </script>
</html>

猜你喜欢

转载自blog.csdn.net/qq_40713201/article/details/126313566