Last active
December 2, 2020 09:26
-
-
Save BenderV/29b83e6d0cc68badd75025d4f46109fe to your computer and use it in GitHub Desktop.
Example Composition Api
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> | |
<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