Created
June 3, 2017 20:49
-
-
Save benjaminoakes/067c165594e78643914f00ba7cee7858 to your computer and use it in GitHub Desktop.
From March 2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Vue.js Sandbox</title> | |
</head> | |
<body> | |
<script src="https://unpkg.com/vue/dist/vue.js"></script> | |
<div id="app"> | |
<button @click="checkAll">Check all</button> | |
<button @click="toggleAll">Toggle all</button> | |
<p> | |
Completed: {{completedCount}} | |
</p> | |
<div> | |
<template v-for="task in tasks"> | |
<input type="checkbox" v-model="task.completed" /> | |
<label>{{ task.text }}</label> | |
<br /> | |
</template> | |
</div> | |
</div> | |
<script> | |
new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello Vue.js!', | |
tasks: [ | |
{ | |
text: "Take out recycling", | |
completed: false, | |
}, | |
{ | |
text: "Charge car", | |
completed: false, | |
} | |
] | |
}, | |
computed: { | |
completedCount: function () { | |
return this.tasks.filter(function (task) { return task.completed; }).length; | |
} | |
}, | |
methods: { | |
checkAll: function () { | |
this.tasks = this.tasks.map(function (task) { | |
task.completed = true; | |
return task; | |
}); | |
}, | |
toggleAll: function () { | |
this.tasks = this.tasks.map(function (task) { | |
task.completed = !task.completed; | |
return task; | |
}); | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment