@@ -15,16 +15,13 @@ We can use the `v-for` directive to render a list of items based on an array. Th
15
15
```
16
16
17
17
``` js
18
- Vue .createApp ().mount (
19
- {
20
- data () {
21
- return {
22
- items: [{ message: ' Foo' }, { message: ' Bar' }]
23
- }
24
- }
25
- },
26
- ' #example-1'
27
- )
18
+ Vue .createApp ({
19
+ data () {
20
+ return {
21
+ items: [{ message: " Foo" }, { message: " Bar" }]
22
+ };
23
+ }
24
+ }).mount (" #example-1" );
28
25
```
29
26
30
27
Result:
@@ -42,17 +39,14 @@ Inside `v-for` blocks we have full access to parent scope properties. `v-for` al
42
39
```
43
40
44
41
``` js
45
- Vue .createApp ().mount (
46
- {
47
- data () {
48
- return {
49
- parentMessage: ' Parent' ,
50
- items: [{ message: ' Foo' }, { message: ' Bar' }]
51
- }
52
- }
53
- },
54
- ' #example-2'
55
- )
42
+ Vue .createApp ({
43
+ data () {
44
+ return {
45
+ parentMessage: " Parent" ,
46
+ items: [{ message: " Foo" }, { message: " Bar" }]
47
+ };
48
+ }
49
+ }).mount (" #example-2" );
56
50
```
57
51
58
52
Result:
@@ -78,20 +72,17 @@ You can also use `v-for` to iterate through the properties of an object.
78
72
```
79
73
80
74
``` js
81
- Vue .createApp ().mount (
82
- {
83
- data () {
84
- return {
85
- myObject: {
86
- title: ' How to do lists in Vue' ,
87
- author: ' Jane Doe' ,
88
- publishedAt: ' 2016-04-10'
89
- }
75
+ Vue .createApp ({
76
+ data () {
77
+ return {
78
+ myObject: {
79
+ title: " How to do lists in Vue" ,
80
+ author: " Jane Doe" ,
81
+ publishedAt: " 2016-04-10"
90
82
}
91
- }
92
- },
93
- ' #v-for-object'
94
- )
83
+ };
84
+ }
85
+ }).mount (" #v-for-object" );
95
86
```
96
87
97
88
Result:
@@ -318,53 +309,49 @@ Here's a complete example of a simple todo list:
318
309
```
319
310
320
311
``` js
321
- const TodoItem = {
312
+ const app = Vue .createApp ({
313
+ data () {
314
+ return {
315
+ newTodoText: " " ,
316
+ todos: [
317
+ {
318
+ id: 1 ,
319
+ title: " Do the dishes"
320
+ },
321
+ {
322
+ id: 2 ,
323
+ title: " Take out the trash"
324
+ },
325
+ {
326
+ id: 3 ,
327
+ title: " Mow the lawn"
328
+ }
329
+ ],
330
+ nextTodoId: 4
331
+ };
332
+ },
333
+ methods: {
334
+ addNewTodo () {
335
+ this .todos .push ({
336
+ id: this .nextTodoId ++ ,
337
+ title: this .newTodoText
338
+ });
339
+ this .newTodoText = " " ;
340
+ }
341
+ }
342
+ });
343
+
344
+ app .component (" todo-item" , {
322
345
template: `
323
346
<li>
324
347
{{ title }}
325
348
<button v-on:click="$emit('remove')">Remove</button>
326
349
</li>
327
350
` ,
328
- props: [' title' ]
329
- }
351
+ props: [" title" ]
352
+ });
330
353
331
- Vue .createApp ().mount (
332
- {
333
- components: {
334
- ' todo-item' : TodoItem
335
- },
336
- data () {
337
- return {
338
- newTodoText: ' ' ,
339
- todos: [
340
- {
341
- id: 1 ,
342
- title: ' Do the dishes'
343
- },
344
- {
345
- id: 2 ,
346
- title: ' Take out the trash'
347
- },
348
- {
349
- id: 3 ,
350
- title: ' Mow the lawn'
351
- }
352
- ],
353
- nextTodoId: 4
354
- }
355
- },
356
- methods: {
357
- addNewTodo () {
358
- this .todos .push ({
359
- id: this .nextTodoId ++ ,
360
- title: this .newTodoText
361
- })
362
- this .newTodoText = ' '
363
- }
364
- }
365
- },
366
- ' #todo-list-example'
367
- )
354
+ app .mount (" #todo-list-example" );
368
355
```
369
356
370
357
<list-7 />
0 commit comments