Skip to content

Instantly share code, notes, and snippets.

@coltborg
Created December 6, 2019 23:51
Show Gist options
  • Save coltborg/817b3cc5a1e1846ac59e02836cf22427 to your computer and use it in GitHub Desktop.
Save coltborg/817b3cc5a1e1846ac59e02836cf22427 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Modularizing
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 };
}
<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