Last active
November 16, 2024 17:30
-
-
Save JeffreyWay/5ecd3f5dad31b7ea3027edcf4834ccab to your computer and use it in GitHub Desktop.
Learn Vue 3: Step by Step, Episode 3, Lists, Conditionals, and Computed Properties - https://laracasts.com/series/learn-vue-3-step-by-step/episodes/3
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 lang="en" class="h-full"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Episode 3: Lists and Computed Properties</title> | |
<script src="https://unpkg.com/vue@3"></script> | |
<script src="https://cdn.tailwindcss.com"></script> | |
</head> | |
<body class="h-full grid place-items-center"> | |
<div id="app"> | |
<section v-show="inProgressAssignments.length"> | |
<h2 class="font-bold mb-2">In Progress</h2> | |
<ul> | |
<li | |
v-for="assignment in inProgressAssignments" | |
:key="assignment.id" | |
> | |
<label> | |
{{ assignment.name }} | |
<input type="checkbox" v-model="assignment.complete"> | |
</label> | |
</li> | |
</ul> | |
</section> | |
<section v-show="completedAssignments.length" class="mt-8"> | |
<h2 class="font-bold mb-2">Completed</h2> | |
<ul> | |
<li | |
v-for="assignment in completedAssignments" | |
:key="assignment.id" | |
> | |
<label> | |
{{ assignment.name }} | |
<input type="checkbox" v-model="assignment.complete"> | |
</label> | |
</li> | |
</ul> | |
</section> | |
</div> | |
<script> | |
let app = { | |
data() { | |
return { | |
assignments: [ | |
{ name: 'Finish project', complete: false, id: 1 }, | |
{ name: 'Read Chapter 4', complete: false, id: 2 }, | |
{ name: 'Turn in Homework', complete: false, id: 3 }, | |
] | |
} | |
}, | |
computed: { | |
inProgressAssignments() { | |
return this.assignments.filter(assignment => ! assignment.complete); | |
}, | |
completedAssignments() { | |
return this.assignments.filter(assignment => assignment.complete); | |
} | |
} | |
}; | |
Vue.createApp(app).mount('#app'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice the HTML duplication and method names with compound words. We'll solve both of those issues in episode 4.