Skip to content

Instantly share code, notes, and snippets.

@coltborg
Last active December 6, 2019 01:19
Show Gist options
  • Save coltborg/9c1bed4b5ae09f73d73e9d4ecbbf905a to your computer and use it in GitHub Desktop.
Save coltborg/9c1bed4b5ae09f73d73e9d4ecbbf905a to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Computed properties
<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 { ref, computed } from "vue";
export default {
setup() {
const capacity = ref(3);
const attending = ref(['Colt', 'Raina', 'John']);
const spacesLeft = computed(() => {
return capacity.value - attending.value.length;
});
fucntion increaseCapacity() {
capacity.value++;
}
return { capacity, increaseCapacity, spacesLeft };
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment