Skip to content

Commit 72ef92d

Browse files
committed
make component examples clearer in guide index
1 parent b14d3b6 commit 72ef92d

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/guide/index.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ The component system is another important concept in Vue, because it's an abstra
249249
In Vue, a component is essentially a Vue instance with pre-defined options. Registering a component in Vue is straightforward:
250250

251251
``` js
252-
Vue.component('todo', {
252+
// Define a new component called todo-item
253+
Vue.component('todo-item', {
253254
template: '<li>This is a todo</li>'
254255
})
255256
```
@@ -258,14 +259,21 @@ Now you can compose it in another component's template:
258259

259260
``` html
260261
<ul>
261-
<todo v-for="todo in todos"></todo>
262+
<!--
263+
Create an instance of the todo-item component
264+
for each todo in a todos array
265+
-->
266+
<todo-item v-for="todo in todos"></todo-item>
262267
</ul>
263268
```
264269

265270
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](/guide/components.html#Props):
266271

267272
``` js
268-
Vue.component('todo', {
273+
Vue.component('todo-item', {
274+
// The todo-item component now accepts a
275+
// "prop", which is like a custom attribute.
276+
// This prop is called todo.
269277
props: ['todo'],
270278
template: '<li>{{ todo.text }}</li>'
271279
})
@@ -276,7 +284,11 @@ Now we can pass the todo into each repeated component using `v-bind`:
276284
``` html
277285
<div id="app-7">
278286
<ol>
279-
<todo v-for="todo in todos" v-bind:todo="todo"></todo>
287+
<!--
288+
Now we provide each todo-item with the todo object
289+
it's representing, so that its content can be dynamic
290+
-->
291+
<todo-item v-for="todo in todos" v-bind:todo="todo"></todo-item>
280292
</ol>
281293
</div>
282294
```
@@ -291,11 +303,11 @@ var app7 = new Vue({
291303
{% raw %}
292304
<div id="app-7" class="demo">
293305
<ol>
294-
<todo v-for="todo in todos" v-bind:todo="todo"></todo>
306+
<todo-item v-for="todo in todos" v-bind:todo="todo"></todo-item>
295307
</ol>
296308
</div>
297309
<script>
298-
Vue.component('todo', {
310+
Vue.component('todo-item', {
299311
props: ['todo'],
300312
template: '<li>{{ todo.text }}</li>'
301313
})
@@ -312,7 +324,7 @@ var app7 = new Vue({
312324
</script>
313325
{% endraw %}
314326

315-
This is just a contrived example, but we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the props interface. We can now further improve our `<todo>` component with more complex template and logic without affecting the parent app.
327+
This is just a contrived example, but we have managed to separate our app into two smaller units, and the child is reasonably well-decoupled from the parent via the props interface. We can now further improve our `<todo-item>` component with more complex template and logic without affecting the parent app.
316328

317329
In a large application, it is necessary to divide the whole app into components to make development manageable. We will talk a lot more about components [later in the guide](/guide/components.html), but here's an (imaginary) example of what an app's template might look like with components:
318330

0 commit comments

Comments
 (0)