You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+27-5
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,31 @@ See [live demo](https://codesandbox.io/s/nuxt-components-cou9k) or [video exampl
68
68
69
69
## Dynamic Components
70
70
71
-
In order to use [dynamic components](https://vuejs.org/v2/guide/components.html#Dynamic-Components) such as `<component :is="myComponent" />`, you need to use the [global option](#global).
71
+
In order to use [dynamic components](https://vuejs.org/v2/guide/components.html#Dynamic-Components) such as `<component :is="myComponent" />`, there is two options:
72
+
- Using `components/global/` directory
73
+
- Setting a custom path with the [global option](#global)
74
+
75
+
### Using `components/global/`
76
+
77
+
> This feature is only available in Nuxt `v2.14.8` or by upgrading this module to `v1.2.0`
78
+
79
+
Any component inside `components/global/` will be available globally (with lazy import) so you can directly use them in your dynamic components.
80
+
81
+
```bash
82
+
components/
83
+
global/
84
+
Home.vue
85
+
Post.vue
86
+
```
87
+
88
+
You can now use `<component>`:
89
+
90
+
```html
91
+
<component:is="'Home'" />
92
+
<component:is="'Post'" />
93
+
```
94
+
95
+
### Using global option
72
96
73
97
Considering this directory structure:
74
98
@@ -77,7 +101,6 @@ components/
77
101
dynamic/
78
102
Home.vue
79
103
Post.vue
80
-
Archive.vue
81
104
```
82
105
83
106
In our `nuxt.config` file, we add this path with `global: true` option:
@@ -94,9 +117,8 @@ export default {
94
117
We can now use our dynamic components in our templates:
95
118
96
119
```html
97
-
<divv-for="name in ['Home', 'Post', 'Archive']":key="name">
98
-
<component:is="name"></component>
99
-
</div>
120
+
<component:is="'Home'" />
121
+
<component:is="'Post'" />
100
122
```
101
123
102
124
Please note that the `global` option does not means components are added to main chunk but they are dynamically imported with webpack, [read more](#global).
0 commit comments