Created
February 1, 2021 18:21
-
-
Save sonicoder86/213bdb11eab710ede8654f8f527b3300 to your computer and use it in GitHub Desktop.
Write Vue like you write React - part 2
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 { defineComponent, ref, watchEffect } from 'vue'; | |
export const Counter = defineComponent({ | |
props: ['limit', 'onLimit'], | |
setup(props) { | |
const count = ref(0); | |
const handler = () => count.value++; | |
watchEffect( | |
() => (count.value >= props.limit) ? props.onLimit() : null | |
); | |
return () => <button type="button" onClick={handler}> | |
Count: {count.value} | |
</button>; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment