![]() Watched properties can often be confused with computed properties, because they operate in a similar way. ![]() ![]() They aren't exactly twins, but they both:īut how do you know which one to use in a given situation? Which one do you use? Watched props are executed whenever a prop changes Computed props are evaluated lazily, meaning they are only executed when they are needed to be used.Computed props are cached, so they only recalculate when things change.Computed props can react to changes in multiple props, whereas watched props can only watch one at a time.Computed props create new reactive properties, watched props only call functions.Computed props should be pure: return a value, synchronous, and have no side-effects.Computed props are more declarative than watched properties.When building components in Vue, we often need to respond to changes in our props.Ī watcher - or watched prop - let's us track a property on our component and run a function whenever it changes.įor example, if the prop colour changes, we can decide to log something to the console: export default Īnd now we only need to write this.importantValue to get ahold of it! Differences and Similarities
0 Comments
Leave a Reply. |