Created
December 4, 2019 17:19
-
-
Save coltborg/8ce35f0c8955f252cbac68c58e5e0844 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Setup & reactive references
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>Capacity: {{ capacity }}</div> | |
</template> | |
<script> | |
import { ref } from 'vue'; | |
export default { | |
setup() { | |
const capacity = ref(3); // Ref is used to wrap a primitive (number) inside of a reactive reference (object) | |
return { capacity }; // Expose to template | |
}, | |
}; | |
</script> |
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
<script> | |
import { watch } from 'vue'; | |
export default { | |
props: { | |
name: String, | |
}, | |
setup(props) { | |
watch(() => { | |
console.log(props.name); | |
}); | |
}, | |
}; | |
</script> |
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>Capacity: {{ capacity }}</div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
capacity: 3, | |
}; | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment