-
-
Save uno-de-piera/8616638d5adc609f19c37c939a8eb3b3 to your computer and use it in GitHub Desktop.
Composable SimpleCounter
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
import { ref, computed } from "@vue/composition-api"; | |
export default function composableSimpleCounter () { | |
const counter = ref(0); | |
const increment = () => { | |
counter.value++; | |
}; | |
const decrement = () => { | |
counter.value--; | |
}; | |
const counterComputed = computed(() => { | |
if (counter.value === 0) return counter.value; | |
return counter.value > 0 ? `+${counter.value}` : `${counter.value}`; | |
}); | |
return { counter, counterComputed, increment, decrement }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment