Last active
March 13, 2019 19:47
-
-
Save GerardRodes/5f72e05e1fb549161ed50a6b558a75e9 to your computer and use it in GitHub Desktop.
Bad implementation
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
<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