Last active
October 14, 2023 19:44
-
-
Save JeffreyWay/9ca33e4213c9e7c66cf3319eecc7b8a6 to your computer and use it in GitHub Desktop.
Learn Vue 3: Step By Step, Ep 27 - Build and Fill a Team Store - https://laracasts.com/series/learn-vue-3-step-by-step/episodes/27
This file contains 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
{ | |
"name": "Smiley", | |
"spots": 5, | |
"members": [ | |
{ | |
"name": "John Doe", | |
"email": "[email protected]", | |
"status": "Active" | |
}, | |
{ | |
"name": "Sarah Doe", | |
"email": "[email protected]", | |
"status": "Active" | |
}, | |
{ | |
"name": "Steve Doe", | |
"email": "[email protected]", | |
"status": "Active" | |
}, | |
{ | |
"name": "Jen Doe", | |
"email": "[email protected]", | |
"status": "Active" | |
}, | |
{ | |
"name": "Joe Doe", | |
"email": "[email protected]", | |
"status": "Active" | |
} | |
] | |
} |
This file contains 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
import { defineStore } from "pinia"; | |
export let useTeamStore = defineStore('team', { | |
state: () => ({ | |
name: '', | |
spots: 0, | |
members: [] | |
}), | |
actions: { | |
async fill() { | |
let r = await import('@/team.json'); | |
this.$state = r.default; | |
}, | |
grow(spots) { | |
this.spots = spots; | |
} | |
}, | |
getters: { | |
spotsRemaining() { | |
return this.spots - this.members.length; | |
} | |
} | |
}); |
This file contains 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
<script setup> | |
import TeamHeader from "@/components/Teams/TeamHeader.vue"; | |
import TeamMembers from "@/components/Teams/TeamMembers.vue"; | |
import TeamFooter from "@/components/Teams/TeamFooter.vue"; | |
import { useTeamStore } from "@/stores/TeamStore"; | |
let team = useTeamStore(); | |
team.fill(); | |
// Example of calling a store action. | |
setTimeout(() => { | |
team.grow(25); | |
}, 2000); | |
</script> | |
<template> | |
<TeamHeader /> | |
<div class="place-self-center flex flex-col gap-y-3" style="width: 725px"> | |
<TeamMembers /> | |
</div> | |
<TeamFooter /> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment