0
0
Vueframework~5 mins

Typing ref and reactive in Vue - Cheat Sheet & Quick Revision

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

ref creates a reactive reference to a single value. It lets Vue track changes to that value and update the UI automatically.

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

reactive makes an entire object reactive, tracking changes to all its properties, while ref tracks a single value.

Click to reveal answer
intermediate
How do you type a ref holding a number in Vue with TypeScript?
<p>Use <code>const count = ref&lt;number&gt;(0)</code> to tell TypeScript the value inside <code>count</code> is a number.</p>
Click to reveal answer
intermediate
How do you type a reactive object with specific properties in Vue?

Define an interface for the object shape, then use reactive<MyInterface>({ ... }) to type it.

Click to reveal answer
beginner
Why do you sometimes need to use .value with ref but not with reactive?

ref wraps a value inside an object, so you access the actual value with .value. reactive returns a proxy of the object itself, so you access properties directly.

Click to reveal answer
Which Vue function creates a reactive object that tracks all its properties?
Areactive
Bwatch
Ccomputed
Dref
How do you access the value inside a ref in Vue?
AUsing .reactive property
BDirectly by variable name
CUsing .value property
DUsing .get() method
What TypeScript syntax is used to type a ref holding a string?
Aref('string')
Bref(string)
Cref: string
Dref&lt;string&gt;('')
Which is true about reactive in Vue?
AIt only works with primitive values
BIt returns a proxy object
CYou must use .value to access properties
DIt is used to create computed properties
If you want to track a number that changes over time, which Vue API is best?
Aref
Breactive
Cwatch
Dcomputed
Explain how to use ref and reactive in Vue with TypeScript typing.
Think about single values vs objects and how TypeScript knows their types.
You got /5 concepts.
    Describe why you need to use .value with ref but not with reactive in Vue.
    Consider how Vue tracks changes differently for single values and objects.
    You got /4 concepts.