Skip to content

Instantly share code, notes, and snippets.

@benjaminoakes
Created June 3, 2017 20:49
Show Gist options
  • Save benjaminoakes/067c165594e78643914f00ba7cee7858 to your computer and use it in GitHub Desktop.
Save benjaminoakes/067c165594e78643914f00ba7cee7858 to your computer and use it in GitHub Desktop.
From March 2017
<!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