<script src="https://npmcdn.com/vue/dist/vue.js"></script>
<div id="exercise">
<!-- 1) Show a "result" of 'not there yet' as long as "value" is not equal to 37 - you can change "value" with the buttons. Print 'done' once you did it -->
<div>
<p>Current Value: {{ value }}</p>
<button @click="value += 5">Add 5</button>
<button @click="value += 1">Add 1</button>
<p>{{ result }}</p>
</div>
<!-- 2) Watch for changes in the "result" and reset the "value" after 5 seconds (hint: setTimeout(..., 5000) -->
<div>
<input type="text">
<p>{{ value }}</p>
</div>
</div>
Vue
new Vue({
el: '#exercise',
data: {
value: 0
},
computed: {
result() {
if (this.value != 37) {
return 'not there yet'
}
return 'done'
}
},
watch: {
result() {
var vm = this;
setTimeout( () => {
vm.value = 0;
}, 5000)
}
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.