I am struggling to make the background color return to its default after 3 seconds using the setTimeout method. How can I adjust my code to achieve this successfully, or should I consider using a transition instead?
<div id="exercise">
<div>
<p>Current Value: {{ value }}</p>
<button @click="value += 5(); red();" :style="{ 'background-color': color }">Add 5</button>
<button @click="value += 1">Add 1</button>
<p>{{ result }}</p>
</div>
<div>
<input type="text" v-model="timer">
<p>{{ value }}</p>
</div>
</div>
new Vue({
el: "#exercise",
data: {
value: 0,
timer: 1000,
color:'pink',
},
methods:{
red() {
this.color = "red";
setTimeout(function() {
this.red = 0;
}, 1000);
}
},
computed: {
result: function() {
return this.value >= 37 ? "Not there yet" : "done";
}
},
watch: {
result: function(value) {
var vm = this;
console.log(value);
setTimeout(function() {
vm.value = 0;
}, 5000);
}
}
});