Skip to content

Commit 1ea42cb

Browse files
author
ntepluhina
committed
fix: changed global component example
1 parent 990e4ae commit 1ea42cb

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

src/guide/introduction.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,16 @@ The component system is another important concept in Vue, because it's an abstra
211211
In Vue, a component is essentially a Vue instance with pre-defined options. Registering a component in Vue is straightforward: we create a component object as we did with `App` objects and we define it in parent's `components` option:
212212

213213
```js
214-
// Define a new component called todo-item
215-
const TodoItem = {
216-
template: '<li>This is a todo</li>'
217-
}
214+
// Create Vue application
215+
const app = Vue.createApp()
218216

219-
const App = {
220-
components: {
221-
'todo-item': TodoItem
222-
}
223-
}
217+
// Define a new component called todo-item
218+
app.component('todo-item', {
219+
template: `<li>This is a todo</li>`
220+
})
224221

225-
Vue.createApp().mount(...)
222+
// Mount Vue application
223+
app.mount(...)
226224
```
227225

228226
Now you can compose it in another component's template:
@@ -237,10 +235,10 @@ Now you can compose it in another component's template:
237235
But this would render the same text for every todo, which is not super interesting. We should be able to pass data from the parent scope into child components. Let's modify the component definition to make it accept a [prop](TODO:components.html#Props):
238236

239237
```js
240-
const TodoItem = {
238+
app.component('todo-item', {
241239
props: ['todo'],
242-
template: '<li>{{ todo.text }}</li>'
243-
}
240+
template: `<li>{{ todo.text }}</li>`
241+
})
244242
```
245243

246244
Now we can pass the todo into each repeated component using `v-bind`:
@@ -264,10 +262,12 @@ Now we can pass the todo into each repeated component using `v-bind`:
264262
```
265263

266264
```js
267-
const TodoItem = {
265+
const app = Vue.createApp()
266+
267+
app.component('todo-item', {
268268
props: ['todo'],
269-
template: '<li>{{ todo.text }}</li>'
270-
}
269+
template: `<li>{{ todo.text }}</li>`
270+
})
271271

272272
const App7 = {
273273
data() {
@@ -278,13 +278,10 @@ const App7 = {
278278
{ id: 2, text: 'Whatever else humans are supposed to eat' }
279279
]
280280
}
281-
},
282-
components: {
283-
'todo-item': TodoItem
284281
}
285282
}
286283

287-
Vue.createApp().mount(App7, '#app-7')
284+
app.mount(App7, '#app-7')
288285
```
289286

290287
<intro-7/>

0 commit comments

Comments
 (0)