Skip to content

Instantly share code, notes, and snippets.

@coltborg
Created December 6, 2019 01:18
Show Gist options
  • Save coltborg/b4d989b64918db3e7dd3cf672a428368 to your computer and use it in GitHub Desktop.
Save coltborg/b4d989b64918db3e7dd3cf672a428368 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - The reactive syntax
<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