Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Last active June 24, 2019 14:20
Show Gist options
  • Select an option

  • Save bravo-kernel/e5d13cd2983642db1a7cf80d431d1d6f to your computer and use it in GitHub Desktop.

Select an option

Save bravo-kernel/e5d13cd2983642db1a7cf80d431d1d6f to your computer and use it in GitHub Desktop.
Feathers-vuex mapActions and mapGetters
<template>
<div id="projects">
<h1>Projects</h1>
<p>
Data will be inserted here from the API, or death !
</p>
<ul class="mt-5">
<li
v-for="project in projects"
:key="project.id"
>
{{ project.id }} = {{ project.name }} ({{ project.companyName }})
</li>
</ul>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex'
export default {
name: 'Projects',
computed: {
// this mapGetter pulls data from the store (using same query as used by mapAction)
...mapGetters('projects', { findProjectsInStore: 'find' }),
projects () {
return this.findProjectsInStore({ query: {} }).data // only return the `data` node in the API response
}
},
methods: {
...mapActions('projects', { findProjects: 'find' })// pull in the `find` action from the `mapAction` namespace (used to fetch data from the API)
},
created () {
this.findProjects( { query: {} }) // execute `mapAction` above to populate the store with API data
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment