Comparison of listener and computed properties (pure concept)

MK Mack 2021-09-15 09:45:44

Characteristics and differences

  • Vue Of computed This option is mainly used to synchronize the processing of data , and watch This option is mainly used for event dispatch , Asynchronous ;
  • Both can achieve the same effect , But based on their respective characteristics , There are some differences in usage scenarios ;
  • computed Have cache properties , Only when the dependent data changes , The associated data will change , It is suitable for computing or formatting data ;
  • watch Monitor data , Related but not dependent , As long as some data changes , You can process some data or dispatch events and synchronize / Asynchronous execution .

Compute properties

  • Abstract concepts are not easy to understand , With more high-frequency scenes, I am naturally familiar with , Calculation properties are represented as synchronous processing of data ;
  • Installment payments in the financial sector ,P2P Annualized income , With computational properties , You can give priority to computed;
  • You don't need to pay attention to click events or other data , As long as the calculation rules are written in the properties , You can get the corresponding data in real time .

image.png

The listener

  • watch The listener What can be done Compute properties computed Can also do , When does it apply to listeners ?
    • It is mainly applicable to scenarios related to events and interactions , Data changes are conditional , It is suitable for one data to trigger multiple things at the same time ;
    • For example, when the loan limit is greater than the available loan limit , eject toast Tips , And adjust the current loan limit to the maximum ;
    • You can see the change of data and pop-up prompt , If yes, and only if there is a certain amount , Not triggered in real time .

image.png Abstract concept

  • The interactive of events such as pop-up prompt is applicable to watch, Application and of data calculation and character processing computed;
Please bring the original link to reprint ,thank
Similar articles

2021-09-15