1 回答
TA贡献2051条经验 获得超10个赞
我不确定,你的代码片段有什么问题,因为你删除的越来越多,我看不到任何错误。
但这应该绝对有效。请参阅我的最小示例:
<html>
<head>
<script src="https://unpkg.com/vue"></script>
<style>
html,
body {
height: 100%;
}
.red {
background-color: red;
}
.blue {
background-color: blue !important;
}
.green {
background-color: green !important;
}
</style>
</head>
<body>
<div id="example">
<div id="bar" v-bind:class="animation">
{{ hello }}
</div>
</div>
<script>
new Vue({
el: '#example',
data() {
return {
hello: "background-div",
animation: "green"
}
},
methods: {
gainAttention(newVal) {
let last = this.animation;
this.animation = newVal;
setTimeout(() => {
this.animation = last;
}, 1000);
}
},
mounted() {
setTimeout(() => {
this.gainAttention("red");
}, 3000);
setTimeout(() => {
this.gainAttention("blue");
}, 5000)
}
})
</script>
</body>
</html>
如果您发布动画/css,我会为您将它们放在一起。
添加回答
举报