5. State animation
code
<! DOCTYPEhtml>
<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>hello vue</title>
<! Vue library -->
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
const app = Vue.createApp({
data(){
return{
num: 1}},methods: {add(){
// Become 10, I want animation from 1, 2, 3... 10
if(this.num < 10) {const animation = setInterval(() = > {
this.num ++;
if(this.num === 10) {clearInterval(animation); }},100); }}},template: ` < div > < div > {{num}} < / div > < button @ click = "add" > add < / button > < / div > `
});
const vm = app.mount('#root');
</script>
</html>
Copy the code