Skip to content

Instantly share code, notes, and snippets.

@GerardRodes
Last active March 13, 2019 19:47
Show Gist options
  • Save GerardRodes/5f72e05e1fb549161ed50a6b558a75e9 to your computer and use it in GitHub Desktop.
Save GerardRodes/5f72e05e1fb549161ed50a6b558a75e9 to your computer and use it in GitHub Desktop.
Bad implementation
<template>
<div>
<ul>
<li v-for="item in results" :key="item.id">
{{ item.name }}
</li>
</ul>
<Checkbox v-model="filters.isNew" />
<Pagination v-model="page" />
</div>
</template>
<script>
export default {
name: 'ResultsPage',
data: () => ({
results: [],
page: 1,
filters: {
isNew: false
}
}),
watch: {
page (page) {
this.fetchResults({ page })
},
filters: {
deep: true,
handler (filters) {
this.fetchResults({ filters })
}
}
},
created () {
this.fetchResults()
},
methods: {
async fetchResults ({ filters = this.filters, page = this.page }) {
const { data: results } = await SomeApiCall({ filters , page })
this.results = results
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment