0
0
Vueframework~5 mins

Ref and reactive in Composition API in Vue - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is ref in Vue's Composition API?

ref creates a reactive reference to a simple value like a number, string, or boolean. It wraps the value so Vue can track changes and update the UI.

Click to reveal answer
beginner
How does reactive differ from ref?

reactive makes an entire object reactive, tracking changes to its properties, while ref is for single primitive values or objects wrapped in a reference.

Click to reveal answer
beginner
How do you access the value inside a ref?

You access or update the value inside a ref using the .value property, for example: count.value = 5.

Click to reveal answer
intermediate
Can you use reactive with arrays and objects?

Yes, reactive works with objects and arrays, making all nested properties reactive so Vue tracks changes deeply.

Click to reveal answer
intermediate
Why might you choose ref over reactive for a single value?

ref is simpler and clearer for single primitive values. It also works better with template syntax and when you want to track a single piece of data.

Click to reveal answer
Which Vue Composition API function creates a reactive object?
Areactive
Bref
Ccomputed
Dwatch
How do you update the value inside a ref variable named count?
Acount.update(newValue)
Bcount = newValue
Ccount.value = newValue
Dcount.set(newValue)
Which is true about reactive in Vue?
AIt only works with primitive values
BIt creates a reactive wrapper for objects and arrays
CIt requires manual updates to trigger reactivity
DIt cannot track nested properties
When should you prefer ref over reactive?
AFor large objects with many properties
BWhen you want to disable reactivity
CWhen you want to track arrays deeply
DFor single primitive values
What happens if you forget to use .value with a ref in your template?
AVue automatically unwraps <code>ref</code> in templates
BThe template will not update reactively
CThe value will update but not render
DVue will throw an error
Explain the difference between ref and reactive in Vue's Composition API.
Think about when you want to track one value versus many properties.
You got /4 concepts.
    Describe how you would make a number reactive and update it in a Vue component using Composition API.
    Remember the syntax: const count = ref(0); count.value = 5;
    You got /3 concepts.