Skip to content

Instantly share code, notes, and snippets.

@BenderV
Last active December 2, 2020 09:26
Show Gist options
  • Save BenderV/29b83e6d0cc68badd75025d4f46109fe to your computer and use it in GitHub Desktop.
Save BenderV/29b83e6d0cc68badd75025d4f46109fe to your computer and use it in GitHub Desktop.
Example Composition Api
<template>
<div>{{ formattedUserLabel }}</div>
<div>{{ counter }}</div>
</template>
<script>
import { ref, computed } from "vue";
export default {
name: "MyComponent",
setup() {
// Counter feature
const counter = ref(0);
const plusOne = () => {
counter.value += 1;
};
// User feature
const user = ref({ name: "Rudy", lastName: "G." });
const formattedUserLabel = computed(() => `${user.value.name} - ${user.value.lastName}`);
return { counter, plusOne, formattedUserLabel };
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment