生命周期
https://vue3js.cn/docs/zh/guide/instance.html#%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E9%92%A9%E5%AD%90
https://vue3js.cn/docs/zh/guide/composition-api-lifecycle-hooks.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 | <template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<h1>{{ count }}</h1>
<h1>{{ double }}</h1>
<ul>
<li v-for="number in numbers" :key="number">
<h1>{{ number }}</h1>
</li>
<h1>{{ person.name }}</h1>
</ul>
<button @click="increase">👍+1</button>
</div>
</template>
<script lang="ts">
import { computed, reactive, toRefs, onMounted, onUpdated, onRenderTriggered } from 'vue';
interface DataProps {
count: number;
double: number;
increase: () => void;
numbers: number[];
person: { name?: string };
}
export default ({
name: 'App',
setup() {
onMounted(() => {
console.log('mounted')
})
onUpdated(() => {
console.log('updated')
})
onRenderTriggered((event) => {
console.log(event)
})
const data: DataProps = reactive({
count: 0,
increase: () => { data.count++ },
double: computed(() => data.count * 2),
numbers: [0, 1, 2],
person: {}
})
data.numbers[0] = 5
data.person.name = 'caiji'
const refData = toRefs(data)
return {
...refData
}
}
});
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
|