Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 752e1a9

Browse files
committed
Update fragments question
1 parent b446b74 commit 752e1a9

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

‎README.md‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,15 +929,25 @@ List of 300 VueJS Interview Questions
929929
**[⬆ Back to Top](#table-of-contents)**
930930

931931
28. ### When component needs a single root element?
932-
Every component must have a single root element **when template has more than one element**. In this case, you need to wrap the elements with a parent element.
932+
In VueJS 2.x, every component must have a single root element **when template has more than one element**. In this case, you need to wrap the elements with a parent element.
933933
```vue
934-
<div class="todo-item">
935-
<h2>{{ title }}</h2>
936-
<div v-html="content"></div>
937-
</div>
934+
<template>
935+
<div class="todo-item">
936+
<h2>{{ title }}</h2>
937+
<div v-html="content"></div>
938+
</div>
939+
</template>
938940
```
939941
Otherwise there will an error throwing, saying that "Component template should contain exactly one root element...".
940942

943+
Whereas in 3.x, components now can have multiple root nodes. This way of adding multiple root nodes is called as fragments.
944+
```vue
945+
<template>
946+
<h2>{{ title }}</h2>
947+
<div v-html="content"></div>
948+
</template>
949+
```
950+
941951
**[⬆ Back to Top](#table-of-contents)**
942952

943953
29. ### How do you communicate from child to parent using events?

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /