mirror of
https://github.com/IT4Change/boilerplate-frontend.git
synced 2025-12-13 07:35:53 +00:00
fix hydration error, ClientOnly component
This commit is contained in:
parent
193777635e
commit
e97b8133de
13
src/components/ClientOnly.vue
Normal file
13
src/components/ClientOnly.vue
Normal 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>
|
||||
@ -14,22 +14,30 @@
|
||||
<div v-if="page === undefined">
|
||||
<h1>The Counter</h1>
|
||||
<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>
|
||||
</div>
|
||||
<div v-else-if="page === 'inc'">
|
||||
<h1>Increase the Counter</h1>
|
||||
<ClientOnly>
|
||||
<v-btn elevation="2" @click="counter.increment()">{{ counter.count }}</v-btn>
|
||||
</ClientOnly>
|
||||
</div>
|
||||
<div v-else-if="page === 'reset'">
|
||||
<h1>Reset the Counter</h1>
|
||||
<ClientOnly>
|
||||
<v-btn elevation="2" @click="counter.reset()">{{ counter.count }}</v-btn>
|
||||
</ClientOnly>
|
||||
</div>
|
||||
</template>
|
||||
</DefaultLayout>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import ClientOnly from '#components/ClientOnly.vue'
|
||||
import DefaultLayout from '#layouts/DefaultLayout.vue'
|
||||
import { useCounterStore } from '#stores/counter'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user