Skip to content

Instantly share code, notes, and snippets.

@BenderV
Created December 2, 2020 09:26
Show Gist options
  • Save BenderV/3fe05faf0543c08f35c5165c7dbfdff5 to your computer and use it in GitHub Desktop.
Save BenderV/3fe05faf0543c08f35c5165c7dbfdff5 to your computer and use it in GitHub Desktop.
Composition API: extraction functions
<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