Getters instead of accessing state directly

This commit is contained in:
Unknown
2019-06-22 20:07:11 +02:00
parent ba47943934
commit 6912a96f21
2 changed files with 10 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ export default {
} }
}, },
created() { created() {
this.categories = this.$store.state.data.resources.map(({ title, slug }) => ({ title, slug })) this.categories = this.$store.getters['data/resources'].map(({ title, slug }) => ({ title, slug }))
} }
} }
</script> </script>

View File

@@ -36,11 +36,13 @@ export const state = () => ({
}) })
export const getters = { export const getters = {
findResources: state => title => { tags: state => state.tags,
return state.resources.find(resource => resource.title.toLowerCase() === title.toLowerCase()) resources: state => state.resources,
}, findResources: state => title => {
findByTags: state => tags => { return state.resources.find(resource => resource.title.toLowerCase() === title.toLowerCase())
const flat = state.resources.map(category => category.resources).flat() },
return flat.filter(resource => resource.tags && includesElOf(resource.tags, tags)) findByTags: state => tags => {
} const flat = state.resources.map(category => category.resources).flat()
return flat.filter(resource => resource.tags && includesElOf(resource.tags, tags))
}
} }