状态动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <script src="../js/vue.js"></script>
    <style>
 
    </style>

</head>
<body>
   
    <div id="root"></div>
     
    <script>  
       // 状态动画
       var app = Vue.createApp({
            data(){
                return {
                    number:1,
                    animateNumber:1
                }  
            },
            methods:{
                handleClick(){
                   this.number = 10
                   if(this.animateNumber < this.number){
                        const animation= setInterval(() => {
                            this.animateNumber += 1
                            if(this.animateNumber === 10){
                                clearInterval(animation)
                            }
                        }, 100);
                   }
                }
            },
            template:`  
                <div>{{animateNumber}}</div>
                <button @click="handleClick">增加</button>    
            `,  

        }).mount('#root')    

    </script>

</body>
</html>
posted @ 2021-12-07 15:36  13522679763-任国强  阅读(24)  评论(0)    收藏  举报