Skip to content

Commit 4d607a7

Browse files
committed
feat(vue-3): render README.md in app
1 parent a08b9ae commit 4d607a7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

vue-3/App.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const users = reactive<{
1616
value?: User[];
1717
loading: boolean;
1818
}>({ loading: false });
19+
const readmeHTML = ref<string | undefined>(undefined);
1920
2021
async function fetchUsers(signal: AbortSignal) {
2122
users.loading = true;
@@ -49,6 +50,21 @@ async function fetchPosts(userId: number, signal: AbortSignal) {
4950
}
5051
}
5152
53+
async function fetchReadme(signal: AbortSignal) {
54+
try {
55+
const [{ marked }, readmeMarkdown] = await Promise.all([
56+
import("https://esm.sh/*marked@17.0.0"),
57+
fetch("./README.md", { signal }).then((res) => res.text()),
58+
]);
59+
const html = await marked.parse(readmeMarkdown);
60+
signal.throwIfAborted();
61+
readmeHTML.value = html;
62+
} catch (error) {
63+
if (signal.aborted) return;
64+
throw error;
65+
}
66+
}
67+
5268
watchEffect(function updateUsers() {
5369
const ctrl = new AbortController();
5470
onWatcherCleanup(() => ctrl.abort());
@@ -61,10 +77,16 @@ watchEffect(function updatePosts() {
6177
onWatcherCleanup(() => ctrl.abort());
6278
fetchPosts(selectedUserId.value, ctrl.signal);
6379
});
80+
81+
watchEffect(function updateReadme() {
82+
const ctrl = new AbortController();
83+
onWatcherCleanup(() => ctrl.abort());
84+
fetchReadme(ctrl.signal);
85+
});
6486
</script>
6587

6688
<template>
67-
<h1>Buildless Vue 3 app</h1>
89+
<section v-html="readmeHTML"></section>
6890
<label v-if="users.value">
6991
Select User:
7092
<select v-model.number="selectedUserId">

0 commit comments

Comments
 (0)