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: src/guide/components.md
+25-2Lines changed: 25 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,16 +135,39 @@ var MyComponent = Vue.extend({
135
135
136
136
The `el` option also requires a function value when used in `Vue.extend()`, for exactly the same reason.
137
137
138
-
### `is` attribute
138
+
### Template Parsing
139
139
140
-
Some HTML elements, for example `<table>`, have restrictions on what elements can appear inside them. Custom elements that are not in the whitelist will be hoisted out and thus not render properly. In such cases you should use the `is` special attribute to indicate a custom element:
140
+
Vue.js template engine is DOM-based and uses native parser that comes with the browser instead of providing a custom one. There are benefits to this approach when compared to string-based template engines, but there are also caveats. Templates have to be individually valid pieces of HTML. Some HTML elements have restrictions on what elements can appear inside them. Most common of these restrictions are:
141
+
142
+
-`a` can not contain other interactive elements (e.g. buttons and other links)
143
+
-`li` should be a direct child of `ul` or `ol`, and both `ul` and `ol` can only contain `li`
144
+
-`option` should be a direct child of `select`, and `select` can only contain `option` (and `optgroup`)
145
+
-`table` can only contain `thead`, `tbody`, `tfoot` and `tr`, and these elements should be direct cildren of `table`
146
+
-`tr` can only contain `th` and `td`, and these elements should be direct children of `tr`
147
+
148
+
In practive these restriction can cause unexpected behavior. Although in simple cases it might appear to work, you can not rely on custom elements being expanded before browser validation. E.g. `<my-select><option>...</option></my-select>` is not a valid template even if `my-select` component eventually expands to `<select>...</select>`.
149
+
150
+
Another consequence is that you can not use custom tags (including custom elements and special tags like `<component>`, `<template>` and `<partial>`) inside of `ul`, `select`, `table` and other elements with similar restrictions. Custom tags will be hoisted out and thus not render properly.
151
+
152
+
In case of a custom element you should use the `is` special attribute:
141
153
142
154
```html
143
155
<table>
144
156
<tris="my-component"></tr>
145
157
</table>
146
158
```
147
159
160
+
In case of a `<template>` inside of a `<table>` you should use `<tbody>`, as tables are allowed to have multiple `tbody`:
0 commit comments