Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Last active January 19, 2020 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/8616638d5adc609f19c37c939a8eb3b3 to your computer and use it in GitHub Desktop.
Save uno-de-piera/8616638d5adc609f19c37c939a8eb3b3 to your computer and use it in GitHub Desktop.
Composable SimpleCounter
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