Characteristics and differences

  • The VuecomputedOption is mainly used to synchronize the processing of data, whilewatchOption is mainly used for event distribution, which can be asynchronous;
  • Both can achieve the same effect, but there are some differences based on their characteristics;
  • computedWith cache attributes, only when the dependent data changes, the associated data will change, suitable for computing or formatting data scenarios;
  • Watch Monitor dataAs long as some data changes, some data can be processed or events can be dispatched and executed synchronously/asynchronously.

Calculate attribute

  • Abstract concept is not easy to understand, with more high-frequency scenes naturally familiar with the calculation of attributes for synchronous processing of data;
  • Installment payments in the financial field, P2P annualized returns, with computational nature, can be given prioritycomputed;
  • There is no need to pay attention to click events or other data, as long as the calculation rules are written in the property, the corresponding data can be obtained in real time.

The listener

  • Watch the listenerYou can doComputed attribute computedYou can do that, too. When do you apply listeners?
    • It is mainly applicable to the scenes related to events and interactions. Data changes are conditions, and it is suitable for one data to trigger multiple things at the same time.
    • For example, when the borrowing amount is greater than the borrowing amount, toast prompt will pop up and the current borrowing amount will be adjusted to the maximum;
    • You can see that the change of data is triggered in the popup box, which is triggered only under a certain amount of money, rather than in real time.

Abstract concept

  • Pop-up prompt and other event interaction is applicable towatch, the application of data computation and character processing andThe computed;