computed

Computed is computing attributes, used to calculate the value of an attribute.

  1. No parentheses are required and can be used as properties
  2. 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.

  1. Immediat: ture indicates that the value should be executed immediately as Watch
  2. Deep means to listen deeply for changes in an object
  3. Cache is not supported. Data changes directly trigger corresponding operations

Watch supports asynchronous code while Computed does not.