Skip to content

Commit fcd3746

Browse files
wip(docs): enhance examples
1 parent 32c57d8 commit fcd3746

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

docs/examples.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ _see at [vuejs/rfcs](https://github.com/vuejs/rfcs/pull/231)_
410410
[:top:](#readme)
411411

412412

413-
## Minimalist example (just for the fun)
413+
## Minimalist Hello World example
414414

415415
<!--example:source:minimalist_example-->
416416
```html
@@ -421,18 +421,11 @@ _see at [vuejs/rfcs](https://github.com/vuejs/rfcs/pull/231)_
421421
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue3-sfc-loader.js"></script>
422422
<script>
423423
424-
/* <!-- */
425-
const vueContent = `
426-
<template> Hello World !</template>
427-
`;
428-
/* --> */
429-
430424
const options = {
431425
moduleCache: { vue: Vue },
432-
getFile: () => vueContent,
426+
getFile: () => `<template>Hello World !</template>`,
433427
addStyle: () => {},
434428
}
435-
436429
Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('file.vue', options))).mount(document.body);
437430
438431
</script>
@@ -494,7 +487,7 @@ _see at [vuejs/rfcs](https://github.com/vuejs/rfcs/pull/231)_
494487

495488

496489

497-
## Dynamic component (`:is` Special Attribute)
490+
## Dynamic component (using `:is` Special Attribute)
498491

499492
In the following example we use a trick to preserve reactivity through the `Vue.defineAsyncComponent()` call (see the following [discussion](https://github.com/FranckFreiburger/vue3-sfc-loader/discussions/6))
500493

@@ -672,7 +665,7 @@ In the following example we use a trick to preserve reactivity through the `Vue.
672665

673666

674667

675-
## Example using SFC Custom Blocks for i18n
668+
## Use SFC Custom Blocks for i18n
676669

677670
<!--example:source:custom_block_i18n-->
678671
```html
@@ -739,7 +732,7 @@ In the following example we use a trick to preserve reactivity through the `Vue.
739732
[:top:](#readme)
740733

741734

742-
## Example using getResource() and process the files like webpack does
735+
## Use Options.getResource() and (nearly) process the files like webpack does
743736

744737
<!--example:source:getResource_loaders-->
745738
```html
@@ -772,7 +765,7 @@ In the following example we use a trick to preserve reactivity through the `Vue.
772765
773766
const options = {
774767
moduleCache: {
775-
vue: Vue,
768+
'vue': Vue,
776769
'file!'(content, path, extname, options) {
777770
778771
return String(new URL(path, window.location));
@@ -789,6 +782,7 @@ In the following example we use a trick to preserve reactivity through the `Vue.
789782
790783
switch (extname) {
791784
case '.svg': return source;
785+
default: return undefined; // let vue3-sfc-loader handle this
792786
}
793787
},
794788
getFile(url, options) {
@@ -830,17 +824,10 @@ In the following example we use a trick to preserve reactivity through the `Vue.
830824
}
831825
};
832826
},
833-
addStyle(textContent) {
834-
835-
const style = Object.assign(document.createElement('style'), { textContent });
836-
const ref = document.head.getElementsByTagName('style')[0] || null;
837-
document.head.insertBefore(style, ref);
838-
},
827+
addStyle() { /* unused here */ },
839828
}
840829
841-
const app = Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/main.vue', options)));
842-
app.mount(document.body);
843-
console.log(options.moduleCache)
830+
Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/main.vue', options))).mount(document.body);
844831
845832
</script>
846833
</body>

0 commit comments

Comments
 (0)