Created
December 6, 2019 23:51
-
-
Save coltborg/817b3cc5a1e1846ac59e02836cf22427 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Modularizing
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 { ref, computed } from "vue"; | |
export default function useEventSpace() { | |
const capacity = ref(3); | |
const attending = ref(['Colt', 'Raina', 'John']); | |
const spacesLeft = computed(() => { | |
return capacity.value - attending.value.length; | |
}); | |
function increaseCapacity() { | |
capacity.value++; | |
} | |
return { capacity, increaseCapacity, spacesLeft }; | |
} |
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
<template> | |
<p> | |
Spaces left: {{ spacesLeft }} out of {{ capacity }} | |
</p> | |
<button @click="increaseCapacity">Increase Capacity</button> | |
<h2>Attending</h2> | |
<ul> | |
<li | |
v-for="(name, index) in attending" | |
:key="index" | |
> | |
{{ name }} | |
</li> | |
</ul> | |
</template> | |
<script> | |
import useEventSpace from "@/event-space"; // would normally put inside of a "use/" sub directory | |
export default { | |
setup() { | |
return useEventSpace(); | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment