1. OverviewThe so-called life cycle function is a function that is automatically triggered under certain conditions. 2. Introduction to VUE3 life cycle functions2.1 beforeCreateFunction that will be automatically executed before the VUE instance is generated 2.2 createdFunction that will be automatically executed after the VUE instance is generated 2.3 beforeMountA function that is automatically executed before the component content is rendered to the page 2.4 mountedA function that is automatically executed after the component content is rendered to the page 2.5 beforeUpdateFunction executed before the data in data changes 2.6 updatedFunction executed when the data in data changes 2.7 beforeUnmountFunction executed before the VUE instance is unbound from the element 2.8 unmountedFunction executed after the VUE instance is unbound from the element 3. Code Examples<script src="../vue.global.js"></script> </head> <body> <div id="myDiv"></div> </body> <script> // Lifecycle function: a function that will be automatically executed at a certain time const app = Vue.createApp({ // Create a Vue application instance data() { return { message : "hello" } }, //The function that will be automatically executed before the instance is generated beforeCreate() { alert("beforeCreate") }, //The function created() will be executed automatically after the instance is generated { alert("created") }, // Function that is automatically executed before the component content is rendered to the page beforeMount() { alert("beforeMount: " + document.getElementById("myDiv").innerHTML) }, // Function mounted() that is automatically executed after the component content is rendered to the page { // Automatically execute alert("mounted: " + document.getElementById("myDiv").innerHTML) after binding }, // Execute beforeUpdate() before the data in data changes { alert("beforeUpdate: " + document.getElementById("myDiv").innerHTML); }, // When the data in data changes, execute updated() { alert("updated: " + document.getElementById("myDiv").innerHTML); }, // Function executed before unbinding beforeUnmount() { alert("beforeUnmount: " + document.getElementById("myDiv").innerHTML); }, // Function executed after unbinding unmounted() { alert("unmounted: " + document.getElementById("myDiv").innerHTML); }, // If there is no template, take the child element below the bound element as the template template : "<div>{{message}}</div>" }); // vm is the root component of the vue application const vm = app.mount('#myDiv'); // Bind the element with id myDiv // Update data vm.$data.message = 'hello world!!!'; // Unbind app.unmount(); </script> 4. OverviewThe above is a detailed explanation of Vue3 life cycle functions and methods introduced by the editor. I hope it will be helpful to everyone. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Solve the problem that the borders of the search box and the search button cannot overlap
>>: How to display TIF format images in browser
Designing navigation for a website is like laying...
Netfilter Netfilter is a packet processing module...
Effect Preview Ideas Scroll the current list to t...
Table of contents Why do we need partitions? Part...
Table of contents Preface: 1. Introduction to Use...
Priority The reason why placing the same conditio...
The layui table has multiple rows of data. Throug...
Modify the group to which a user belongs in Linux...
You can manage and deploy Docker containers in a ...
This article example shares the specific code of ...
Because I have always used vscode to develop fron...
Table of contents 1. Parent passes value to child...
You need to add "gt_" in front of the f...
Solution: Directly in the directory where you dow...
This article example shares the specific code of ...