Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created January 19, 2020 11:29
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/a5e688b096790ade60fb771f70be86dd to your computer and use it in GitHub Desktop.
Save uno-de-piera/a5e688b096790ade60fb771f70be86dd to your computer and use it in GitHub Desktop.
<template>
<div>
<h2>Simple Counter</h2>
<p>{{ counter }}</p>
<p>{{ counterComputed }}</p>
<button @click="increment()">Incrementar</button>
<button @click="decrement()">Decrementar</button>
</div>
</template>
<script>
import { ref, computed } from '@vue/composition-api';
export default {
name: "SimpleCounter",
setup () {
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 };
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment