I've been attempting to change the background color of an element upon clicking it using Vue, but so far I haven't had any success. Here's what I have come up with, including a method that has two functions for the onclick event in Vue.
<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>
js
new Vue({
el: "#exercise",
data: {
value: 0,
timer: 1000,
},
methods:{
red() {
this.color = "red";
}
},
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);
}
}
});