-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdemo-vue.html
245 lines (211 loc) · 8.3 KB
/
demo-vue.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
layout: layout.html
title: Vue Islands
---
<h1><a href="/">is-land</a> using <img src="https://v1.indieweb-avatar.11ty.dev/https%3A%2F%2Fvuejs.org%2F/" alt="IndieWeb avatar for https://vuejs.org/" width="28" height="28" decoding="async" loading="lazy"> Vue.js</h1>
<h2>Scroll down</h2>
<hr style="height: 100vh">
<h2><code>on:visible</code></h2>
<h3>Client-rendered petite-vue</h3>
<is-land on:visible autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land on:visible>
<div id="petite-vue-app">
Petite Vue (using an inline script for extra init code)
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</div>
<template data-island>
<script type="module">
import { createApp } from "https://unpkg.com/[email protected]/dist/petite-vue.es.js";
createApp({
count: 0,
}).mount("#petite-vue-app")
</script>
</template>
</is-land>
<h3>Client-rendered Vue.js</h3>
<p>This is the first full Vue component (and it is off-viewport) so the library code is also lazy loaded. The island will eagerly load the library code if it has no loading conditions.</p>
<!-- You can add `import="https://unpkg.com/[email protected]/dist/vue.esm-browser.prod.js"` here if you want the import to finish before the component is declared “ready” -->
<is-land on:visible>
<div id="vue-app">
Vue (using an inline script for extra init code)
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</div>
<template data-island>
<script type="module">
import { createApp } from "https://unpkg.com/[email protected]/dist/vue.esm-browser.prod.js";
createApp({
data: () => ({ count: 0 })
}).mount("#vue-app")
</script>
</template>
</is-land>
<h3>Works with <details></h3>
<details>
<summary>The child content in this <details> will not be initialized until you open it</summary>
<is-land on:visible autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
</details>
<h2><code>on:idle</code></h2>
<p>In this example (under the right conditions) you might be able to see these petite-vue islands wait until the full Vue.js island finishes above (if both are visible)</p>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" on:idle v-scope="{ count: 0 }">
Petite Vue
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
<h2>Fallback content</h2>
<p>If you put child content in a <template> it will be JavaScript-only (no fallback). Use this to your advantage! You can mix and match <template> with other progressively enhanced content in the island.</p>
<is-land on:interaction="mouseenter,focusin">
<p><code>on:interaction</code>: Hover or focus to hydrate the island:</p>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ count: 0 }">
Petite Vue (count fallback content is shown, buttons require JS):
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
</template>
<span v-html="count">0</span>
</is-land>
<template data-island>
<p>This is an island nested in a <template> (it *can* have its own loading conditions!):</p>
<is-land autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ count: 0 }">
Petite Vue (JS is required for fallback):
<template data-island>
<button @click="count++">⬆️</button>
<button @click="count--">⬇️</button>
<span v-html="count">0</span>
</template>
</is-land>
</template>
</is-land>
<h2>Server-rendered Vue (SSR)</h2>
<p>SSR requires server-side integration, in this case provided by Eleventy.</p>
<h3>No hydration, HTML only</h3>
<p>Without hydration, the island is unnecessary.</p>
<div class="demo-component">
{% assign component = "./lib/vue/vue-component-html-only.js" | vue %}
{{ component.html }}
</div>
<h3>With Hydration</h3>
<is-land on:visible>
Increment the counter:
{% assign component = "./lib/vue/vue-component.js" | vue %}
<div id="vue-app-ssr">{{ component.html }}</div>
<template data-island>
<script type="module">
import { createSSRApp } from "https://unpkg.com/[email protected]/dist/vue.esm-browser.prod.js";
import app from "{{ component.clientJsUrl }}";
createSSRApp(app).mount("#vue-app-ssr");
</script>
</template>
</is-land>