Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Last active May 13, 2022 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyWay/0eff7b7fdf903ebc098f640e94eb2eeb to your computer and use it in GitHub Desktop.
Save JeffreyWay/0eff7b7fdf903ebc098f640e94eb2eeb to your computer and use it in GitHub Desktop.
Learn Vue 3: Step By Step, Episode 13 - Lifecycle Hooks, Fake APIs, and AJAX - https://laracasts.com/series/learn-vue-3-step-by-step/episodes/13
import AssignmentList from "./AssignmentList.js";
import AssignmentCreate from "./AssignmentCreate.js";
export default {
components: { AssignmentList, AssignmentCreate },
template: `
<section class="space-y-6">
<assignment-list :assignments="filters.inProgress" title="In Progress"></assignment-list>
<assignment-list :assignments="filters.completed" title="Completed"></assignment-list>
<assignment-create @add="add"></assignment-create>
</section>
`,
data() {
return {
assignments: [],
}
},
computed: {
filters() {
return {
inProgress: this.assignments.filter(assignment => ! assignment.complete),
completed: this.assignments.filter(assignment => assignment.complete)
};
}
},
created() {
fetch('http://localhost:3001/assignments')
.then(response => response.json())
.then(assignments => {
this.assignments = assignments;
});
},
methods: {
add(name) {
this.assignments.push({
name: name,
completed: false,
id: this.assignments.length + 1
});
}
}
}
{
"assignments": [
{
"name": "Finish project",
"complete": false,
"id": 1,
"tag": "math"
},
{
"name": "Read chapter 4",
"complete": false,
"id": 1,
"tag": "science"
},
{
"name": "Turn in homework",
"complete": false,
"id": 1,
"tag": "math"
},
{
"name": "Finish Laracasts video",
"complete": true,
"id": 1,
"tag": "programming"
}
]
}
{
"devDependencies": {
"json-server": "^0.17.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment