当前位置:网站首页>Atguigu---17-life cycle
Atguigu---17-life cycle
2022-06-25 09:04:00 【Zhangshao】
Life cycle introduction
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Lead to the life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Life cycle : 1. also called : Life cycle callback function 、 Life cycle function 、 Lifecycle hook . 2. What is it? :Vue Some special named functions that help us call at the critical moment . 3. 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 . 4. In the life cycle function this The point is vm or Component instance object . -->
<!-- Prepare a container -->
<div id="root">
<h2 v-if="a"> How do you do </h2>
<h2 :style="{opacity}"> Welcome to learn Vue</h2>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', data:{
a:false, opacity:1 }, methods: {
}, //Vue Complete the parsing of the template and put the initial real DOM After the element is placed on the page ( The mount is finished ) call mounted mounted(){
console.log('mounted',this) setInterval(() => {
this.opacity -= 0.01 if(this.opacity <= 0) this.opacity = 1 },16) }, }) // Through the external timer ( Not recommended ) /* setInterval(() => { vm.opacity -= 0.01 if(vm.opacity <= 0) vm.opacity = 1 },16) */ </script>
</html>
Life cycle diagram

Analysis life cycle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Analysis life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Prepare a container -->
<div id="root" :x="n">
<h2 v-text="n"></h2>
<h2> Current n The value is :{
{n}}</h2>
<button @click="add"> Am I n+1</button>
<button @click="bye"> Point I destroy vm</button>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', // template:` // <div> // <h2> Current n The value is :{
{n}}</h2> // <button @click="add"> Am I n+1</button> // </div> // `, data:{
n:1 }, methods: {
add(){
console.log('add') this.n++ }, bye(){
console.log('bye') this.$destroy() } }, watch:{
n(){
console.log('n Changed ') } }, beforeCreate() {
console.log('beforeCreate') }, created() {
console.log('created') }, beforeMount() {
console.log('beforeMount') }, mounted() {
console.log('mounted') }, beforeUpdate() {
console.log('beforeUpdate') }, updated() {
console.log('updated') }, beforeDestroy() {
console.log('beforeDestroy') }, destroyed() {
console.log('destroyed') }, }) </script>
</html>
Summary life cycle
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Lead to the life cycle </title>
<!-- introduce Vue -->
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- Common life cycle hooks : 1.mounted: send out ajax request 、 Start timer 、 Binding custom events 、 Subscribe to news, etc 【 Initialization operation 】. 2.beforeDestroy: Clear timer 、 Unbind custom events 、 Unsubscribe messages, etc 【 Finishing work 】. About destruction Vue example 1. Destroy with the help of Vue Developer tools don't see any information . 2. After destruction, the custom event will become invalid , But the original DOM The event is still valid . 3. Usually not in beforeDestroy Operational data , Because even if you manipulate data , The update process will no longer be triggered . -->
<!-- Prepare a container -->
<div id="root">
<h2 :style="{opacity}"> Welcome to learn Vue</h2>
<button @click="opacity = 1"> Transparency set to 1</button>
<button @click="stop"> Click me to stop the transformation </button>
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // prevent vue Generate production prompts at startup . new Vue({
el:'#root', data:{
opacity:1 }, methods: {
stop(){
this.$destroy() } }, //Vue Complete the parsing of the template and put the initial real DOM After the element is placed on the page ( The mount is finished ) call mounted mounted(){
console.log('mounted',this) this.timer = setInterval(() => {
console.log('setInterval') this.opacity -= 0.01 if(this.opacity <= 0) this.opacity = 1 },16) }, beforeDestroy() {
clearInterval(this.timer) console.log('vm I'm going to travel to the West ') }, }) </script>
</html>
边栏推荐
- LVS-DR模式多网段案例
- Object.defineProperty也能监听数组变化?
- 华泰证券在上面开股票账户安全吗?
- 声纹技术(一):声纹技术的前世今生
- Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an
- OpenFOAM:底层
- Jmeter接口测试,关联接口实现步骤(token)
- Socket programming -- epoll model
- Notes on key words in the original English work biography of jobs (IV) [chapter two]
- CSV parameterization in JMeter
猜你喜欢

行业春寒回暖,持续承压的酒店企业于何处破局?
![[untitled] * * database course design: complete the student information management system in three days**](/img/69/762819fa1b11085a7e36c95acbe880.png)
[untitled] * * database course design: complete the student information management system in three days**

Oracle one line function Encyclopedia

How to design test cases

C language: find all integers that can divide y and are odd numbers, and put them in the array indicated by B in the order from small to large

WebGL谷歌提示内存不够(RuntimeError:memory access out of bounds,火狐提示索引超出界限(RuntimeError:index out of bounds)

Matplotlib plt grid()

Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed

In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World

RMB 3000 | record "tbtools" video, make a friend and get a cash prize!
随机推荐
How annotation lib and processor lib reference
2、 Training fashion_ MNIST dataset
How can games copied from other people's libraries be displayed in their own libraries
行业春寒回暖,持续承压的酒店企业于何处破局?
紧急行政中止令下达 Juul暂时可以继续在美国销售电子烟产品
[MySQL] understanding of transactions
Object. Can defineproperty also listen for array changes?
四、卷积神经网络(Convolution Neural Networks)
In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World
Prepare for the 1000 Android interview questions and answers that golden nine silver ten must ask in 2022, and completely solve the interview problems
5、 Project practice --- identifying man and horse
声纹技术(一):声纹技术的前世今生
JMeter interface test, associated interface implementation steps (token)
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
从别人库里拷贝的游戏如何再自己的库里显示
compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
Matplotlib simple logistic regression visualization
Unity发布webGL的时候JsonConvert.SerializeObject()转换失败
某次比赛wp
3、 Automatically terminate training