fix hydration error, ClientOnly component

This commit is contained in:
Ulf Gebhardt 2023-11-23 17:06:43 +01:00
parent 193777635e
commit e97b8133de
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 24 additions and 3 deletions

View File

@ -0,0 +1,13 @@
<template>
<template v-if="isMounted"><slot /></template>
<template v-else><slot name="placeholder" /></template>
</template>
<script setup>
import { ref, onMounted } from 'vue'
const isMounted = ref(false)
onMounted(() => {
isMounted.value = true
})
</script>

View File

@ -14,22 +14,30 @@
<div v-if="page === undefined"> <div v-if="page === undefined">
<h1>The Counter</h1> <h1>The Counter</h1>
<p> <p>
The current value of the counter is: <b>{{ counter.count }}</b> The current value of the counter is:
<ClientOnly
><b>{{ counter.count }}</b></ClientOnly
>
</p> </p>
</div> </div>
<div v-else-if="page === 'inc'"> <div v-else-if="page === 'inc'">
<h1>Increase the Counter</h1> <h1>Increase the Counter</h1>
<ClientOnly>
<v-btn elevation="2" @click="counter.increment()">{{ counter.count }}</v-btn> <v-btn elevation="2" @click="counter.increment()">{{ counter.count }}</v-btn>
</ClientOnly>
</div> </div>
<div v-else-if="page === 'reset'"> <div v-else-if="page === 'reset'">
<h1>Reset the Counter</h1> <h1>Reset the Counter</h1>
<ClientOnly>
<v-btn elevation="2" @click="counter.reset()">{{ counter.count }}</v-btn> <v-btn elevation="2" @click="counter.reset()">{{ counter.count }}</v-btn>
</ClientOnly>
</div> </div>
</template> </template>
</DefaultLayout> </DefaultLayout>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import ClientOnly from '#components/ClientOnly.vue'
import DefaultLayout from '#layouts/DefaultLayout.vue' import DefaultLayout from '#layouts/DefaultLayout.vue'
import { useCounterStore } from '#stores/counter' import { useCounterStore } from '#stores/counter'