-
-
Save uno-de-piera/a5e688b096790ade60fb771f70be86dd to your computer and use it in GitHub Desktop.
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
<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