Last active
July 15, 2021 19:08
-
-
Save petervmeijgaard/8c4481d3e59f0102dcdc35edd9ce6be3 to your computer and use it in GitHub Desktop.
Writing Reusable Vue Composables - Introduction - Composition API
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> | |
<p>My Number - {{ myNumber }}</p> | |
<p>Parent Number - {{ parentNumber}} - {{ parentNumberPlusOne }}</p> | |
<button @click="addNumber()"> | |
Add | |
</button> | |
</div> | |
</template> | |
<script> | |
import { computed, ref } from 'vue'; | |
export default { | |
name: 'AsCompositionApi', | |
props: { | |
parentNumber: { | |
type: Number, | |
required: true, | |
}, | |
}, | |
setup(props) { | |
const myNumber = ref(1); | |
const addNumber = () => { | |
myNumber.value += 1; | |
}; | |
const myNumberPlusOne = computed(() => props.parentNumber.value + 1); | |
return { | |
myNumber, | |
addNumber, | |
myNumberPlusOne, | |
}; | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment