Skip to content

Commit 11787da

Browse files
wip: add Nested components example.
1 parent 4a9e566 commit 11787da

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

docs/examples.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,105 @@ In the following example we use a trick to preserve reactivity through the `Vue.
520520

521521

522522

523+
524+
## Nested components
525+
526+
<!--example:source:nested_components-->
527+
```html
528+
<!DOCTYPE html>
529+
<html>
530+
<body>
531+
<script src="https://unpkg.com/vue@next"></script>
532+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue3-sfc-loader.js"></script>
533+
<script>
534+
535+
/* <!-- */
536+
const config = {
537+
files: {
538+
'/main.vue': `
539+
<template>
540+
<foo/>
541+
</template>
542+
<script>
543+
import foo from './foo.vue'
544+
545+
export default {
546+
components: {
547+
foo,
548+
},
549+
created() {
550+
console.log('main created')
551+
},
552+
mounted() {
553+
console.log('main mounted')
554+
}
555+
}
556+
</script>
557+
`,
558+
559+
'/foo.vue': `
560+
<template>
561+
<bar/>
562+
</template>
563+
<script>
564+
import bar from './bar.vue'
565+
566+
export default {
567+
components: {
568+
bar,
569+
},
570+
created() {
571+
console.log('foo created')
572+
},
573+
mounted() {
574+
console.log('foo mounted')
575+
}
576+
}
577+
</script>
578+
`,
579+
580+
'/bar.vue': `
581+
<template>
582+
end
583+
</template>
584+
<script>
585+
586+
export default {
587+
components: {
588+
},
589+
created() {
590+
console.log('bar created')
591+
},
592+
mounted() {
593+
console.log('bar mounted')
594+
}
595+
}
596+
</script>
597+
`
598+
}
599+
};
600+
/* --> */
601+
602+
603+
const options = {
604+
moduleCache: { vue: Vue },
605+
getFile: url => config.files[url],
606+
addStyle: () => {},
607+
}
608+
609+
Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/main.vue', options))).mount(document.body);
610+
611+
</script>
612+
</body>
613+
</html>
614+
```
615+
<!--example:target:nested_components-->
616+
<!--/example:target:nested_components-->
617+
[:top:](#readme)
618+
619+
620+
621+
523622
<!---
524623
525624
const regexpReservedChars = '\\.+*?^$|[{()';

0 commit comments

Comments
 (0)