Skip to content

Commit 1db20ef

Browse files
committed
made it clearer that Vue.component sets the component's name
1 parent df84111 commit 1db20ef

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/api/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ type: api
249249

250250
- **Usage:**
251251

252-
Register or retrieve a global component.
252+
Register or retrieve a global component. Registration also automatically sets the component's `name` with the given `id`.
253253

254254
``` js
255255
// register an extended constructor

src/guide/components.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,26 @@ Again, this _only_ works within string templates, as self-closing custom element
981981

982982
Components can recursively invoke themselves in their own template. However, they can only do so with the `name` option:
983983

984+
``` js
985+
name: 'unique-name-of-my-component'
986+
```
987+
988+
When you register a component globally using `Vue.component`, the global ID is automatically set as the component's `name` option.
989+
990+
``` js
991+
Vue.component('unique-name-of-my-component', {
992+
// ...
993+
})
994+
```
995+
996+
If you're not careful, recursive components can also lead to infinite loops:
997+
984998
``` js
985999
name: 'stack-overflow',
9861000
template: '<div><stack-overflow></stack-overflow></div>'
9871001
```
9881002

989-
A component like the above will result in a "max stack size exceeded" error, so make sure recursive invocation is conditional (i.e. uses a `v-if` that will eventually be false). When you register a component globally using `Vue.component`, the global ID is automatically set as the component's `name` option.
1003+
A component like the above will result in a "max stack size exceeded" error, so make sure recursive invocation is conditional (i.e. uses a `v-if` that will eventually be `false`).
9901004

9911005
### Inline Templates
9921006

0 commit comments

Comments
 (0)