4
votes

If I need to access a computed property 20 times in one function, is it better to assign the value of it to a local variable first?

Would that improve performance?

1
It would be a microoptimization.Ohgodwhy
DRY when you use a same value over and over again IMO it's better to it stored in variable instead of referencing it everytime like, obj.whateverCode Maniac
Improve performance: No, since the value already exists and given that the computed property dependencies don't change while this function that uses it 20 times. (And really DRY is the way to go even with negligible performance tradeoffs isn't it.)ambianBeing

1 Answers

5
votes

Computed properties are cached based on their reactive dependencies ... Computed Caching vs Methods

Vue.js automatically cache the computed value, as long as their reactive dependencies don't mutate.

Storing it in a variable would be counter-intuitive.