Last active
March 17, 2021 13:27
-
-
Save mtimbs/ee93fa16939e910948d40f683e6ade06 to your computer and use it in GitHub Desktop.
Example of data coupling in Vue component
This file contains hidden or 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
// TODO's Index | |
<template> | |
<ToDo v-for="todo in todos" :data="todo"/> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
todos: [] | |
} | |
}, | |
mounted() { | |
this.fetchToDos() | |
}, | |
methods: { | |
async fetchToDos() { | |
this.todos = this.$api.get('todos?status=pending') | |
} | |
} | |
} | |
</script> | |
// Recently Completed ToDos Summary | |
<template> | |
<ToDo v-for="todo in todos" :data="todo"/> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
todos: [] | |
} | |
}, | |
mounted() { | |
this.fetchToDos() | |
}, | |
methods: { | |
async fetchToDos() { | |
this.todos = this.$api.get('todos?status=complete&order=desc&limit=5') | |
} | |
} | |
} | |
</script> | |
// Single ToDo View | |
<template> | |
// not relevant | |
</template> | |
<script> | |
export default { | |
props: { | |
id: { | |
type: String, | |
require: true, | |
default: '' | |
}, | |
}, | |
data() { | |
return { | |
todo: {} | |
} | |
}, | |
mounted() { | |
this.fetchToDo() | |
}, | |
methods: { | |
async fetchToDos() { | |
this.todos = this.$api.get(`todos/${this.id}`) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment