Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the life cycle function in Vue

Shulou Source: shulou.com Published: 2022-06-01 08:35:41 10月04日 Update

This article mainly shows you "what is the life cycle function in Vue", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the life cycle function in Vue" this article.

Life cycle function

Life cycle function is also called: life cycle callback function, life cycle function, life cycle hook

What is it: Vue calls some functions with special names for us at critical moments

The name of the lifecycle function cannot be changed, but the specific content of the function is written by the programmer according to the requirements.

The this in the lifecycle function points to the vm or component instantiation object.

Commonly used life cycle hooks

1. Mounted: send ajax request, start timer, bind custom event subscription message and other functions [initialization]

2. BeforeDestory: clear timer, unbind custom events, unsubscribe messages, etc. [start and end]

About Vue terminating an instance:

1. After destruction, you cannot see any information with the help of Vue developer tools.

2. After termination, the custom event will fail, but the native DOM event is still valid.

3. Generally, data will not be manipulated in beforeDestory, because even if data is manipulated, the update process will no longer be triggered.

Welcome to learn the life cycle point of Vue. I stop changing Vue.config.productionTip = false. Const vm = new Vue ({el:'# root', data: {opacity: 1,}, methods: {stop () {/ / clearInterval (this.timer) this.$destroy () }}, / / Vue calls mounted mounted () {this.timer = setInterval (()) > {this.opacity-= 0.01; if (this.opacity) after the template parsing is completed and the real initial DOM elements are placed on the page (after loading is completed)

Tags: Cycle life function periodic function event content article learning timer instance data message hook help subscription valid special information element key Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi NVidia MariaDB Shulou Tech Info