You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-5Lines changed: 15 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -929,15 +929,25 @@ List of 300 VueJS Interview Questions
929
929
**[⬆ Back to Top](#table-of-contents)**
930
930
931
931
28. ### When component needs a single root element?
932
-
Every component must have a single root element **when template has more than one element**. Inthis 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**. Inthis case, you need to wrap the elements with a parent element.
933
933
```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>
938
940
```
939
941
Otherwise there will an error throwing, saying that "Component template should contain exactly one root element...".
940
942
943
+
Whereas in3.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
+
941
951
**[⬆ Back to Top](#table-of-contents)**
942
952
943
953
29. ### How do you communicate from child to parent using events?
0 commit comments