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
Table of contents 1. Download the installation pa...
123WORDPRESS.COM provides you with the FileZilla ...
Table of contents getting Started Data storage Co...
The figure below shows the browser viewing rate i...
Table of contents 1. Overview 2. Parameters for c...
If your DOCTYPE is as follows: Copy code The code ...
Table of contents 1. Where is the slowness? 2. Ha...
The Internet is already saturated with articles o...
Table of contents Introduction to bootstrap and i...
background The popularity of Docker is closely re...
Preface: The Linux host is relatively easy to han...
Table of contents 1. Introduction 2. Installation...
1. Transactions have ACID characteristics Atomici...
Preface During the stress test, if the most direc...
1. Link layout of the new site homepage 1. The loc...