File tree Expand file tree Collapse file tree 1 file changed +52
-6
lines changed Expand file tree Collapse file tree 1 file changed +52
-6
lines changed Original file line number Diff line number Diff line change 7
7
8
8
Nest SFCs within your SFC.
9
9
10
- ## Usage
10
+ ## Install
11
11
12
12
Install package:
13
13
@@ -34,9 +34,9 @@ export default {
34
34
};
35
35
```
36
36
37
- Add volar plugin for IDE support
37
+ Add volar plugin for IDE support:
38
38
39
- ``` json
39
+ ``` jsonc
40
40
// tsconfig.app.json
41
41
{
42
42
" vueCompilerOptions" : {
@@ -45,14 +45,20 @@ Add volar plugin for IDE support
45
45
}
46
46
```
47
47
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.
49
53
50
54
``` html
51
55
<template >
52
- <MyCoolComponent > Hello World! </MyCoolComponent >
56
+ <MyHeader >
57
+ Hello World!
58
+ </MyHeader >
53
59
</template >
54
60
55
- <component name =" MyCoolComponent " lang =" vue" >
61
+ <component name =" MyHeader " lang =" vue" >
56
62
<template >
57
63
<h1 >
58
64
<slot />
@@ -61,6 +67,46 @@ Use inside SFC
61
67
</component >
62
68
```
63
69
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
+
64
110
## License
65
111
66
112
Made with 💛
You can’t perform that action at this time.
0 commit comments