software-development-2022/assignment5-3/app.js

29 lines
490 B
JavaScript
Raw Normal View History

2022-11-17 15:48:17 +01:00
const app = Vue.createApp({
data: () => ({
sum: 0,
timeout: null,
}),
methods: {
add(amount) {
this.sum += amount;
},
},
computed: {
result() {
if (this.sum < 37) return "Not there yet";
if (this.sum > 37) return "Too much!";
return this.number;
},
},
watch: {
sum() {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.sum = 0;
}, 5000);
},
},
});
app.mount("#assignment");