Skip to content

Instantly share code, notes, and snippets.

@coltborg
Created December 4, 2019 17:19
Show Gist options
  • Save coltborg/8ce35f0c8955f252cbac68c58e5e0844 to your computer and use it in GitHub Desktop.
Save coltborg/8ce35f0c8955f252cbac68c58e5e0844 to your computer and use it in GitHub Desktop.
Vue 3 Essentials - Setup & reactive references
<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>
<script>
import { watch } from 'vue';
export default {
props: {
name: String,
},
setup(props) {
watch(() => {
console.log(props.name);
});
},
};
</script>
<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