[Vue] Life cycle, created, mounted, methods, computed, watched, easy to understand

Life cycle:

  • beforecreate: The general usage scenario is when loading events are added
  • created: After loading is over, some initialization is also done to realize function self-execution (data data has been initialized, but the DOM structure rendering is completed, and the component is not loaded)
  • beforemount: The component is created, but the operation has not started
  • mounted: Initiating a back-end request, obtaining data, and performing operations with the routing hook (DOM rendering completed, component mounting completed)
  • beforeupdate, updated: before and after data update
  • beforeDestroy: when the current component is still there, want to delete the component
  • destroyed: The current component has been destroyed, clear the relevant content

The difference between created and mounted

  • created: Called before the template is rendered into html, that is, some attribute values ​​are usually initialized, and then rendered into a view.
  • mounted: Called after the template is rendered into html, usually after the initialization page is completed, some required operations are performed on the dom node of html.

The difference between mounted and methods

  • mounted is one of the life cycle methods, which will be executed during the corresponding life cycle.

  • Methods are methods bound to Vue instance objects for use within the scope of the current Vue component. They will not be executed if they are not called, only logic is executed, and the return value is optional.

The difference between computed and watched

  • computed is a computational attribute, and can also be understood as a method. If the result of the calculation does not change, it will not be triggered, and a value must be returned and bound in the DOM to get the value. He can automatically obtain data changes.

  • The watched attribute is a manually defined value that needs to be monitored. Different data can be defined multiple times in the watched value. At this time, it will consume a certain amount of performance and it cannot be automatically changed like computed.

Guess you like

Origin blog.csdn.net/qq_22227087/article/details/87256833