0
0
Vueframework~5 mins

Reactive objects with reactive in Vue - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the reactive function do in Vue?
It creates a reactive object that Vue tracks for changes, so the UI updates automatically when the object's properties change.
Click to reveal answer
beginner
How do you create a reactive object with Vue's Composition API?
Use <code>import { reactive } from 'vue'</code> and then call <code>const state = reactive({ key: value })</code>.
Click to reveal answer
beginner
Why should you use reactive instead of a plain JavaScript object in Vue?
Because Vue can detect changes in reactive objects and update the UI automatically, while plain objects won't trigger updates.
Click to reveal answer
intermediate
Can you add new properties to a reactive object after creation and have Vue track them?
Yes, Vue 3's reactive system tracks new properties added to reactive objects, so the UI updates when they change.
Click to reveal answer
intermediate
What is the difference between reactive and ref in Vue?
reactive makes an entire object reactive, while ref makes a single value reactive and wraps it in an object with a .value property.
Click to reveal answer
What does Vue's reactive function return?
AA plain JavaScript object
BA function to update state
CA reactive proxy object that tracks changes
DA string representation of the object
Which Vue import is needed to use reactive?
Aimport reactive from 'vuex'
Bimport { ref } from 'vue'
Cimport { reactive } from 'vue-router'
Dimport { reactive } from 'vue'
If you change a property inside a reactive object, what happens?
AVue updates the UI automatically
BNothing, you must refresh manually
CVue throws an error
DThe object becomes non-reactive
Can you use reactive with arrays?
AYes, arrays become reactive objects
BNo, only plain objects work
COnly if you convert arrays to objects first
DOnly with special plugins
What is a key difference between reactive and ref?
A<code>reactive</code> is for strings only
B<code>ref</code> wraps a single value, <code>reactive</code> wraps an object
C<code>ref</code> cannot be used in templates
D<code>reactive</code> does not track changes
Explain how Vue's reactive function helps keep the UI updated automatically.
Think about how Vue watches for changes in data.
You got /4 concepts.
    Describe the difference between using reactive and ref in Vue's Composition API.
    Consider what kind of data each is best for.
    You got /4 concepts.