vue3-core/playground/src/App.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
1.5 KiB
Vue
Raw Normal View History

2023-11-17 03:01:19 +08:00
<script setup lang="ts">
import {
ref,
computed,
onMounted,
onBeforeMount,
2023-12-29 22:11:33 +08:00
getCurrentInstance,
onBeforeUpdate,
onUpdated,
onRenderTracked,
onRenderTriggered,
} from 'vue/vapor'
2023-11-17 03:01:19 +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--
onBeforeMount(() => {
console.log('onBeforeMount', instance.isMounted)
})
onMounted(() => {
console.log('onMounted', instance.isMounted)
})
onMounted(() => {
setTimeout(() => {
count.value++
}, 1000)
})
onBeforeUpdate(() => {
console.log('before updated')
})
onUpdated(() => {
console.log('updated')
})
onRenderTracked(e => {
console.log(`Render Tracked:`, e.target)
})
onRenderTriggered(e => {
console.log(`Render trigger:`, e.target)
})
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>
<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>