0
0
Vueframework~5 mins

Computed vs method performance in Vue - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a computed property in Vue?
A computed property is a reactive value that Vue caches based on its dependencies. It only recalculates when its dependencies change, improving performance by avoiding unnecessary recalculations.
Click to reveal answer
beginner
How does a method differ from a computed property in Vue?
A method runs every time it is called during rendering, without caching. This means it recalculates on each render, which can be less efficient than computed properties for expensive calculations.
Click to reveal answer
intermediate
Why are computed properties generally better for performance than methods in Vue?
Computed properties cache their results and only update when dependencies change, reducing unnecessary recalculations. Methods run fresh every render, which can slow down the app if the calculation is heavy.
Click to reveal answer
intermediate
When should you use a method instead of a computed property in Vue?
Use a method when you need to perform an action that should run fresh every time, like event handlers or when the result depends on arguments passed at call time.
Click to reveal answer
advanced
What happens if a computed property has no reactive dependencies?
If a computed property has no reactive dependencies, it will compute once and cache that value indefinitely, behaving like a constant until the component is destroyed.
Click to reveal answer
Which Vue feature caches its result until dependencies change?
AMethod
BComputed property
CWatchers
DDirectives
How often does a Vue method run during rendering?
AEvery time it is called during render
BOnly when manually triggered
COnce when the component mounts
DOnly when dependencies change
When is it better to use a method instead of a computed property?
AFor expensive calculations
BWhen caching is needed
CWhen the result depends on arguments passed at call time
DFor reactive data binding
What is a downside of using methods for expensive calculations in Vue?
AThey cannot access reactive data
BThey do not run on every render
CThey cache results unnecessarily
DThey recalculate every render, which can hurt performance
If a computed property has no reactive dependencies, what happens?
AIt computes once and caches indefinitely
BIt recalculates every render
CIt never runs
DIt throws an error
Explain the performance differences between computed properties and methods in Vue.
Think about when Vue recalculates values and how caching helps.
You got /4 concepts.
    Describe when you should choose a method over a computed property in Vue and why.
    Consider if the calculation depends on arguments or needs caching.
    You got /4 concepts.