Skip to content

Commit ca4340c

Browse files
author
ntepluhina
committed
fix: fixed list rendering
1 parent 20eb82a commit ca4340c

File tree

1 file changed

+61
-74
lines changed

1 file changed

+61
-74
lines changed

src/guide/list.md

Lines changed: 61 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ We can use the `v-for` directive to render a list of items based on an array. Th
1515
```
1616

1717
```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");
2825
```
2926

3027
Result:
@@ -42,17 +39,14 @@ Inside `v-for` blocks we have full access to parent scope properties. `v-for` al
4239
```
4340

4441
```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");
5650
```
5751

5852
Result:
@@ -78,20 +72,17 @@ You can also use `v-for` to iterate through the properties of an object.
7872
```
7973

8074
```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"
9082
}
91-
}
92-
},
93-
'#v-for-object'
94-
)
83+
};
84+
}
85+
}).mount("#v-for-object");
9586
```
9687

9788
Result:
@@ -318,53 +309,49 @@ Here's a complete example of a simple todo list:
318309
```
319310

320311
```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", {
322345
template: `
323346
<li>
324347
{{ title }}
325348
<button v-on:click="$emit('remove')">Remove</button>
326349
</li>
327350
`,
328-
props: ['title']
329-
}
351+
props: ["title"]
352+
});
330353

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");
368355
```
369356

370357
<list-7/>

0 commit comments

Comments
 (0)