Skip to content

Commit f66d6b3

Browse files
committed
docs: add export example
1 parent 0bf448e commit f66d6b3

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

README.md

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Nest SFCs within your SFC.
99

10-
## Usage
10+
## Install
1111

1212
Install package:
1313

@@ -34,9 +34,9 @@ export default {
3434
};
3535
```
3636

37-
Add volar plugin for IDE support
37+
Add volar plugin for IDE support:
3838

39-
```json
39+
```jsonc
4040
// tsconfig.app.json
4141
{
4242
"vueCompilerOptions": {
@@ -45,14 +45,20 @@ Add volar plugin for IDE support
4545
}
4646
```
4747

48-
Use inside SFC
48+
## Usage
49+
50+
### Defining components
51+
52+
Nested components are defined with the `<component>` block. The block's content is treated as if it's a seperate SFC.
4953

5054
```html
5155
<template>
52-
<MyCoolComponent> Hello World! </MyCoolComponent>
56+
<MyHeader>
57+
Hello World!
58+
</MyHeader>
5359
</template>
5460

55-
<component name="MyCoolComponent" lang="vue">
61+
<component name="MyHeader" lang="vue">
5662
<template>
5763
<h1>
5864
<slot />
@@ -61,6 +67,46 @@ Use inside SFC
6167
</component>
6268
```
6369

70+
### Exporting
71+
72+
You can export nested components with the `export` attribute.
73+
74+
```html
75+
<!-- Button.vue -->
76+
<template>
77+
<button>
78+
<slot />
79+
</button>
80+
</template>
81+
82+
<component name="RoundedButton" lang="vue" export>
83+
<template>
84+
<button>
85+
<slot />
86+
</button>
87+
</template>
88+
<style scoped>
89+
button {
90+
border-radius: 20px;
91+
}
92+
</style>
93+
</component>
94+
```
95+
96+
Import them from other files as named exports.
97+
98+
```html
99+
<!-- App.vue -->
100+
<script setup>
101+
import { RoundedButton } from "./components/Button.vue";
102+
</script>
103+
<template>
104+
<RoundedButton>
105+
Click me
106+
</RoundedButton>
107+
</template>
108+
```
109+
64110
## License
65111

66112
Made with 💛

0 commit comments

Comments
 (0)