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
> Note: this section only affects cases where Vue templates are directly written in the page's HTML.
460
-
461
-
-**Expects:** string literal
462
-
463
-
-**Limited to:** native HTML elements
464
-
465
-
-**Usage:** When using in-DOM templates, the template is subject to native HTML parsing rules. Some HTML elements, such as `<ul>`, `<ol>`, `<table>` and `<select>` have restrictions on what elements can appear inside them, and some elements such as `<li>`, `<tr>`, and `<option>` can only appear inside certain other elements. As a workaround, we can use `v-is` directive on these elements:
466
-
467
-
```html
468
-
<table>
469
-
<trv-is="'blog-post-row'"></tr>
470
-
</table>
471
-
```
472
-
473
-
:::warning
474
-
`v-is` functions like a dynamic 2.x `:is` binding - so to render a component by its registered name, its value should be a JavaScript string literal:
475
-
476
-
```html
477
-
<!-- Incorrect, nothing will be rendered -->
478
-
<trv-is="blog-post-row"></tr>
479
-
480
-
<!-- Correct -->
481
-
<trv-is="'blog-post-row'"></tr>
482
-
```
483
-
484
-
:::
459
+
Deprecated in 3.1.0. Use [`is` attribute with `vue:` prefix](/api/special-attributes.html#is) instead.
Used for [dynamic components](../guide/component-dynamic-async.html).
59
+
Used for [dynamic components](../guide/component-dynamic-async.html).
60
60
61
-
For example:
61
+
For example:
62
+
63
+
```html
64
+
<!-- component changes when currentView changes -->
65
+
<component:is="currentView"></component>
66
+
```
67
+
68
+
-**Usage on native elements** <Badgetext="3.1+" />
62
69
63
-
```html
64
-
<!-- component changes when currentView changes -->
65
-
<component:is="currentView"></component>
66
-
```
70
+
When the `is` attribute is used on native HTML elements, it will be interpreted as [Customized built-in elements](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example) which is a native web platform feature.
71
+
72
+
There is, however, a use case where you may need Vue to replace a native element with a Vue component, as explained in [DOM Template Parsing Caveats](/guide/component-basics.html#dom-template-parsing-caveats). You can prefix the value of the `is` attribute with `vue:` so that Vue will render the element as a Vue component instead:
-[RFC explaining the change from Vue 2](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0027-custom-elements-interop.md#customized-built-in-elements)
Copy file name to clipboardExpand all lines: src/guide/component-basics.md
+19-20Lines changed: 19 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -406,6 +406,18 @@ That's all you need to know about dynamic components for now, but once you've fi
406
406
407
407
## DOM Template Parsing Caveats
408
408
409
+
If you are writing your Vue templates directly in the DOM, Vue will have to retrieve the template string from the DOM. This leads to some caveats due to browser's native HTML parsing behavior.
410
+
411
+
:::tip
412
+
It should be noted that the limitations discussed below only applies if you are writing your templates directly in the DOM. They do NOT apply if you are using string templates from the following sources:
Some HTML elements, such as `<ul>`, `<ol>`, `<table>` and `<select>` have restrictions on what elements can appear inside them, and some elements such as `<li>`, `<tr>`, and `<option>` can only appear inside certain other elements.
410
422
411
423
This will lead to issues when using components with elements that have such restrictions. For example:
@@ -416,28 +428,21 @@ This will lead to issues when using components with elements that have such rest
416
428
</table>
417
429
```
418
430
419
-
The custom component `<blog-post-row>` will be hoisted out as invalid content, causing errors in the eventual rendered output. We can use the special `v-is`directive as a workaround:
431
+
The custom component `<blog-post-row>` will be hoisted out as invalid content, causing errors in the eventual rendered output. We can use the special [`is`attribute](/api/special-attributes.html#is) as a workaround:
420
432
421
433
```html
422
434
<table>
423
-
<trv-is="'blog-post-row'"></tr>
435
+
<tris="vue:blog-post-row"></tr>
424
436
</table>
425
437
```
426
438
427
-
:::warning
428
-
The `v-is` value is treated as a JavaScript expression, so we need to wrap the component name in quotes:
429
-
430
-
```html
431
-
<!-- Incorrect, nothing will be rendered -->
432
-
<trv-is="blog-post-row"></tr>
433
-
434
-
<!-- Correct -->
435
-
<trv-is="'blog-post-row'"></tr>
436
-
```
437
-
439
+
:::tip
440
+
When used on native HTML elements, the value of `is` must be prefixed with `vue:` in order to be interpreted as a Vue component. This is required to avoid confusion with native [customized built-in elements](https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-customized-builtin-example).
438
441
:::
439
442
440
-
Also, HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you’re using in-DOM templates, camelCased prop names and event handler parameters need to use their kebab-cased (hyphen-delimited) equivalents:
443
+
### Case Insensivitity
444
+
445
+
HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you’re using in-DOM templates, camelCased prop names and event handler parameters need to use their kebab-cased (hyphen-delimited) equivalents:
441
446
442
447
```js
443
448
// camelCase in JavaScript
@@ -456,12 +461,6 @@ app.component('blog-post', {
456
461
<blog-postpost-title="hello!"></blog-post>
457
462
```
458
463
459
-
It should be noted that **these limitations do _not_ apply if you are using string templates from one of the following sources**:
That's all you need to know about DOM template parsing caveats for now - and actually, the end of Vue's _Essentials_. Congratulations! There's still more to learn, but first, we recommend taking a break to play with Vue yourself and build something fun.
466
465
467
466
Once you feel comfortable with the knowledge you've just digested, we recommend coming back to read the full guide on [Dynamic & Async Components](component-dynamic-async.html), as well as the other pages in the Components In-Depth section of the sidebar.
0 commit comments