-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path生命周期函数的新写法.html
69 lines (53 loc) · 2 KB
/
生命周期函数的新写法.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<p>beforeCreate和created 这两个在composition API中没有 因为setup函数创建时间点就在其上</p>
<p>onRenderTracked 新周期函数 需要收集响应式依赖时执行 每次重渲染时都会收集</P>
<p>onRenderTriggered 每次触发页面重新渲染时执行</p>
<div id="root">
</div>
<script>
const app = Vue.createApp({
// beforeMount => onBeforeMount
// mounted => onMounted
// beforeUpdate => onBeforeUpdate
// beforeUnmount => onBeforeUnmount
setup() {
const { onBeforeMount, onMounted, onBeforeUpdate, onUpdate, onBeforeUnmount,
onRenderTracked, onRenderTriggered
} = Vue;
onBeforeMount(() => {
console.log('onBeforeMount');
})
onMounted(() => {
console.log('onMounted');
})
onBeforeUpdate(() => {
console.log('onBeforeUpdate');
})
onUpdate(() => {
console.log('onUpdate');
})
onRenderTracked(() => {
console.log('onRenderTracked');
})
onRenderTriggered(() => {
console.log('onRenderTriggered');
})
onBeforeUnmount(() => {
console.log('onBeforeUnmount');
})
},
template: `<div>生命周期函数新写法 react的写法</div>`
});
const vm = app.mount('#root');
</script>
</body>
</html>