Created
December 2, 2020 09:26
-
-
Save BenderV/3fe05faf0543c08f35c5165c7dbfdff5 to your computer and use it in GitHub Desktop.
Composition API: extraction functions
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
<script> | |
import { ref } from "vue"; | |
export function useCounter() { | |
const counter = ref(0); | |
const plusOne = () => { counter.value += 1 }; | |
return { counter, plusOne }; | |
} | |
export default { | |
name: "MyComponent", | |
setup() { | |
const { counter, plusOne } = useCounter() | |
return { counter, plusOne } | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment