Created
December 6, 2019 01:18
-
-
Save coltborg/b4d989b64918db3e7dd3cf672a428368 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - The reactive syntax
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 { computed, reactive, toRefs } from "vue"; | |
export default { | |
setup() { | |
const event = reactive({ | |
attending: ['Colt', 'Raina', 'John'], | |
capacity: 4, | |
spacesLeft: computed(() => { | |
return event.capacity - event.attending.length; | |
}), | |
}); | |
fucntion increaseCapacity() { | |
capacity.value++; | |
} | |
return { ...toRefs(event), increaseCapacity }; | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment