// 状态动画
// 中间有一个缓慢的过程
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>hello</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
// 状态动画
// 中间有一个缓慢的过程
// 创建 vue实例
const 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>
<div>{{animateNumber}}</div>
<button @click="handleClick">
增加
</button>
</div>
`
});
const vm = app.mount('#root');
</script>
</html>