1 回答

TA貢獻(xiàn)2051條經(jīng)驗 獲得超10個贊
我不確定,你的代碼片段有什么問題,因為你刪除的越來越多,我看不到任何錯誤。
但這應(yīng)該絕對有效。請參閱我的最小示例:
<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>
如果您發(fā)布動畫/css,我會為您將它們放在一起。
添加回答
舉報