Skip to content

Commit 5bd2a63

Browse files
committed
feat: document is vue: prefix usage, deprecate v-is
1 parent 445e1fa commit 5bd2a63

File tree

3 files changed

+40
-54
lines changed

3 files changed

+40
-54
lines changed

src/api/directives.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -454,31 +454,6 @@
454454
- **See also:**
455455
- [Data Binding Syntax - interpolations](../guide/template-syntax.html#text)
456456

457-
## v-is
457+
## v-is <Badge text="deprecated" type="warning" />
458458

459-
> 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-
<tr v-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-
<tr v-is="blog-post-row"></tr>
479-
480-
<!-- Correct -->
481-
<tr v-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.

src/api/special-attributes.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,27 @@
5656

5757
- **Expects:** `string | Object (component’s options object)`
5858

59-
Used for [dynamic components](../guide/component-dynamic-async.html).
59+
Used for [dynamic components](../guide/component-dynamic-async.html).
6060

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** <Badge text="3.1+" />
6269

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:
73+
74+
```html
75+
<table>
76+
<tr is="vue:my-row-component"></tr>
77+
</table>
78+
```
6779

6880
- **See also:**
6981
- [Dynamic Components](../guide/component-dynamic-async.html)
70-
- [DOM Template Parsing Caveats](../guide/component-basics.html#dom-template-parsing-caveats)
82+
- [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)

src/guide/component-basics.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,18 @@ That's all you need to know about dynamic components for now, but once you've fi
406406

407407
## DOM Template Parsing Caveats
408408

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:
413+
414+
- String templates (e.g. `template: '...'`)
415+
- [Single-file (`.vue`) components](single-file-component.html)
416+
- `<script type="text/x-template">`
417+
:::
418+
419+
### Element Placement Restrictions
420+
409421
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.
410422

411423
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
416428
</table>
417429
```
418430

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:
420432

421433
```html
422434
<table>
423-
<tr v-is="'blog-post-row'"></tr>
435+
<tr is="vue:blog-post-row"></tr>
424436
</table>
425437
```
426438

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-
<tr v-is="blog-post-row"></tr>
433-
434-
<!-- Correct -->
435-
<tr v-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).
438441
:::
439442

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:
441446

442447
```js
443448
// camelCase in JavaScript
@@ -456,12 +461,6 @@ app.component('blog-post', {
456461
<blog-post post-title="hello!"></blog-post>
457462
```
458463

459-
It should be noted that **these limitations do _not_ apply if you are using string templates from one of the following sources**:
460-
461-
- String templates (e.g. `template: '...'`)
462-
- [Single-file (`.vue`) components](single-file-component.html)
463-
- `<script type="text/x-template">`
464-
465464
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.
466465

467466
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

Comments
 (0)