Lifecycle Functions Life cycle functions are also called: life cycle callback functions, life cycle functions, life cycle hooks What is it: Vue helps us call some functions with special names at critical moments The name of the life cycle function cannot be changed, but the specific content of the function is written by the programmer according to the needs This in the lifecycle function refers to vm or component instantiation object Common life cycle hooks 1. 2. About Vue destroy instance: 1. After destruction, no information can be seen with the help of Vue developer tools 2. Custom events will become invalid after destruction, but native DOM events are still valid 3. Generally, data will not be operated in beforeDestory, because even if the data is operated, the update process will no longer be triggered. <div id="root"> <h2 :style="{opacity}"> Welcome to learn Vue's life cycle</h2> <button @click="stop">Click me to stop the change</button> </div> <script> Vue.config.productionTip = false; const vm = new Vue({ el: '#root', data: { opacity: 1, }, methods: { stop() { // clearInterval(this.timer) this.$destroy(); } }, //After Vue completes template parsing and puts the real initial DOM element into the page (mounting is complete), call mounted mounted() { this.timer = setInterval(() => { this.opacity -= 0.01; if (this.opacity <= 0) this.opacity = 1; }, 16) }, beforeDestroy() { console.log('vm is about to travel to the west'); clearInterval(this.timer) } }) </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Nginx reverse proxy configuration to remove prefix case tutorial
>>: A brief discussion on several situations where adding indexes to MySQL does not take effect
Table of contents Overview 1. How to animate a DO...
Today, when I logged into the company's inter...
Table of contents Overview What are Generics Buil...
The pitfalls 1. Many tutorials on the Internet wr...
Table of contents 1. How to find duplicate rows 2...
Preface In actual business, paging is a common bu...
As a super rookie, I just started learning MySQL ...
This article example shares the specific code for...
This tag is not part of HTML3.2 and is only suppo...
This article is mysql database Question 1 Import ...
[Solution 1: padding implementation] principle: I...
First, let me explain the application method. The...
The purpose of using cache is to reduce the press...
1. There are generally two methods for Vue routin...
1. HTML tags with attributes XML/HTML CodeCopy co...