Difference computed, methods, watch the

Three are in common can process data.

Similarities and differences:

methods:

1, is a method, these methods can be accessed by VM instance, or instruction used in the expression. As long as the method is called inside the function will be executed, multiple calls on multiple times, does not depend cache;

2, and methods must have a certain trigger condition to perform, such as a click event.

computed:

1, is a calculated attribute, when invoked, if dependent on the property itself does not change, then no matter how many times the calls are executed only once, and the results of the implementation of cached, when the next call, and direct calls cache As a result, no longer execute code, compared to the more economical methods for performance. Of course, when the property itself has changed, the new code will be executed;

2, computed is performed immediately after the HTML DOM loads, such as assignment.

3, can also monitor changes in the data, but compared to watch it, mainly for simple handling computed synchronization data, if the asynchronous operation involving, use will have to watch, such as the monitor changes the routing parameters.

watch:

1, it is to monitor property. To observe changes and the response data Vue example, mainly for data input or asynchronous operation in the case of large overhead

2, Watch up page will not be implemented, only the specified data will trigger changes, watch unbuffered nature, value does not change is also performed.

 

Guess you like

Origin www.cnblogs.com/hhhhhedy/p/11445659.html