Vue Tip: Props and Context in Setup Method
The setup function in Vue 3 Composition API will take two arguments: props
and context
.
The first argument in the setup
function is the props
argument. props
are reactive and will be updated when new props are passed in.
Warning
You cannot use ES6 destructuring because it will remove props
reactivity. If you want to destructure props
you need to use toRefs.
The second argument in the setup
function is the context
argument. It is a normal JavaScript object that exposes some useful values:
If you liked this Vue tip, follow me on X to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter:
Vue Tip: Detailed Prop Definitions
Define your Vue prop definitions as detailed as possible.
Vue Tip: Avoid Empty Class Attributes
This Vue tip helps to avoid empty class attributes in the rendered HTML