Skip to content

Instantly share code, notes, and snippets.

@mtimbs
Last active March 17, 2021 13:27
Show Gist options
  • Save mtimbs/ee93fa16939e910948d40f683e6ade06 to your computer and use it in GitHub Desktop.
Save mtimbs/ee93fa16939e910948d40f683e6ade06 to your computer and use it in GitHub Desktop.
Example of data coupling in Vue component
// 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