-
Notifications
You must be signed in to change notification settings - Fork 92
/
Homepage.vue
81 lines (72 loc) · 1.73 KB
/
Homepage.vue
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<div>
<h1>This is the homepage. Server's getProps works: {{ server }}</h1>
<p class="test">Message from server: {{ msg }}</p>
<p>{{ homeLocalState }}</p>
</div>
</template>
<script>
import { defineComponent, inject, ref } from 'vue'
import { useHead } from '@vueuse/head'
import { useContext } from 'vite-ssr/vue'
export default defineComponent({
name: 'Homepage',
props: {
server: {
type: Boolean,
default: false,
},
msg: {
type: String,
default: '',
},
name: {
type: String,
default: '',
},
},
async setup() {
const { initialState } = useContext()
// Hydrate from initialState, if there's anything
const homeLocalState = ref(initialState.homeLocalState || null)
useHead({
title: 'Home!',
htmlAttrs: { lang: 'es' },
bodyAttrs: { class: 'dummy test' },
meta: [
{ name: 'description', content: 'This should be moved to head' },
{ property: 'test', content: homeLocalState },
],
link: [{ rel: 'stylesheet' }],
script: [
{
type: 'application/ld+json',
children: JSON.stringify({ something: true }),
},
],
})
if (!homeLocalState.value) {
// No data, get it fresh from any API
homeLocalState.value = await new Promise((resolve) =>
setTimeout(
() => resolve('This is local component state using Suspense'),
500
)
)
if (import.meta.env.SSR) {
// Save this data in SSR initial state for hydration later
initialState.homeLocalState = homeLocalState.value
}
}
return {
homeLocalState,
}
},
})
</script>
<style scoped>
.test {
color: #333;
}
</style>
>