2023-11-17 03:01:19 +08:00
|
|
|
<script setup lang="ts">
|
2023-12-15 01:47:56 +08:00
|
|
|
import {
|
|
|
|
ref,
|
|
|
|
computed,
|
|
|
|
onMounted,
|
|
|
|
onBeforeMount,
|
2023-12-29 22:11:33 +08:00
|
|
|
getCurrentInstance,
|
2024-01-13 03:25:57 +08:00
|
|
|
onBeforeUpdate,
|
|
|
|
onUpdated,
|
2023-12-15 01:47:56 +08:00
|
|
|
} from 'vue/vapor'
|
2023-11-17 03:01:19 +08:00
|
|
|
|
2023-12-15 01:47:56 +08:00
|
|
|
const instance = getCurrentInstance()!
|
2023-11-24 15:25:34 +08:00
|
|
|
const count = ref(1)
|
2023-11-23 23:42:08 +08:00
|
|
|
const double = computed(() => count.value * 2)
|
2023-11-24 14:44:57 +08:00
|
|
|
const html = computed(() => `<button>HTML! ${count.value}</button>`)
|
2023-11-23 23:42:08 +08:00
|
|
|
|
|
|
|
const inc = () => count.value++
|
|
|
|
const dec = () => count.value--
|
2023-12-15 01:47:56 +08:00
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
console.log('onBeforeMount', instance.isMounted)
|
|
|
|
})
|
|
|
|
onMounted(() => {
|
|
|
|
console.log('onMounted', instance.isMounted)
|
|
|
|
})
|
|
|
|
onMounted(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
count.value++
|
|
|
|
}, 1000)
|
|
|
|
})
|
2024-01-13 03:25:57 +08:00
|
|
|
|
|
|
|
onBeforeUpdate(() => {
|
|
|
|
console.log('before updated')
|
|
|
|
})
|
|
|
|
onUpdated(() => {
|
|
|
|
console.log('updated')
|
|
|
|
})
|
|
|
|
|
|
|
|
const log = (arg: any) => {
|
|
|
|
console.log('callback in render effect')
|
|
|
|
return arg
|
|
|
|
}
|
2023-11-17 03:01:19 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
2023-11-23 23:42:08 +08:00
|
|
|
<h1 class="red">Counter</h1>
|
2024-01-13 03:25:57 +08:00
|
|
|
<div>The number is {{ log(count) }}.</div>
|
2023-11-23 23:42:08 +08:00
|
|
|
<div>{{ count }} * 2 = {{ double }}</div>
|
|
|
|
<div style="display: flex; gap: 8px">
|
|
|
|
<button @click="inc">inc</button>
|
|
|
|
<button @click="dec">dec</button>
|
|
|
|
</div>
|
2023-11-24 14:59:10 +08:00
|
|
|
<div v-html="html" />
|
|
|
|
<div v-text="html" />
|
2023-11-24 15:25:34 +08:00
|
|
|
<div v-once>once: {{ count }}</div>
|
2023-11-24 15:37:49 +08:00
|
|
|
<div v-pre>{{ count }}</div>
|
2023-11-24 15:40:38 +08:00
|
|
|
<div v-cloak>{{ count }}</div>
|
2023-11-17 03:01:19 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.red {
|
|
|
|
color: red;
|
|
|
|
}
|
2023-11-23 23:42:08 +08:00
|
|
|
|
|
|
|
html {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
2023-11-17 03:01:19 +08:00
|
|
|
</style>
|