computed
Computed is computing attributes, used to calculate the value of an attribute.
- No parentheses are required and can be used as properties
- Automatic caching based on dependencies, values are not recalculated while dependencies remain unchanged
Getters and setters for computed
- Attributes for computed can be read and set. Therefore, in computed, there are getters (to read) and setters (to set values).
- Generally, there are no setters, and for computed, only getters are preset, so you can only read, not set values. So, computed default format (which does not show getters).
- Setter functions are called when a value is assigned to a calculated property.
watch
Watch means to listen, and when something changes, it listens and executes.
- Immediat: ture indicates that the value should be executed immediately as Watch
- Deep means to listen deeply for changes in an object
- Cache is not supported. Data changes directly trigger corresponding operations
Watch supports asynchronous code while Computed does not.