Last active
December 6, 2019 01:19
-
-
Save coltborg/9c1bed4b5ae09f73d73e9d4ecbbf905a to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Computed properties
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 { 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