Skip to content

Commit 3700e87

Browse files
docs (#156): add inline-template attribute docs to migration guide (#183)
* docs (#156): add inline-template attribute docs to migration guide * docs (#156): add escape hatch Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com> * docs (#156): improve syntax rendering Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com> Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com>
1 parent 2ddec96 commit 3700e87

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const sidebar = {
103103
'migration/functional-components',
104104
'migration/global-api',
105105
'migration/global-api-treeshaking',
106+
'migration/inline-template-attribute',
106107
'migration/keycode-modifiers',
107108
'migration/render-function-api',
108109
'migration/slots-unification',
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
types:
3+
- breaking
4+
- removal
5+
---
6+
7+
# Inline Template Attribute
8+
9+
## Overview
10+
11+
Support for the [inline-template feature](https://vuejs.org/v2/guide/components-edge-cases.html#Inline-Templates) has been removed.
12+
13+
## 2.x Syntax
14+
15+
In 2.x, Vue provided the `inline-template` attribute on child components to use its inner content as its template instead of treating it as distributed content.
16+
17+
```html
18+
<my-component inline-template>
19+
<div>
20+
<p>These are compiled as the component's own template.</p>
21+
<p>Not parent's transclusion content.</p>
22+
</div>
23+
</my-component>
24+
```
25+
26+
## 3.x Syntax
27+
28+
This feature will no longer be supported.
29+
30+
## Migration Strategy
31+
32+
Most of the use cases for `inline-template` assumes a no-build-tool setup, where all templates are written directly inside the HTML page.
33+
34+
### Option #1: Use `<script>` tag
35+
36+
The most straightforward workaround in such cases is using `<script>` with an alternative type:
37+
38+
```js
39+
<script type="text/html" id="my-comp-template">
40+
<div>{{ hello }}</div>
41+
</script>
42+
```
43+
44+
And in the component, target the template using a selector:
45+
46+
```js
47+
const MyComp = {
48+
template: '#my-comp-template'
49+
// ...
50+
}
51+
```
52+
53+
This doesn't require any build setup, works in all browsers, is not subject to any in-DOM HTML parsing caveats (e.g. you can use camelCase prop names), and provides proper syntax highlighting in most IDEs. In traditional server-side frameworks, these templates can be split out into server template partials (included into the main HTML template) for better maintainability.
54+
55+
### Option #2: Default Slot
56+
57+
A component previously using `inline-template` can also be refactored using the default slot - which makes the data scoping more explicit while preserving the convenience of writing child content inline:
58+
59+
```html
60+
<!-- 2.x Syntax -->
61+
<my-comp inline-template :msg="parentMsg">
62+
{{ msg }} {{ childState }}
63+
</my-comp>
64+
65+
<!-- Default Slot Version -->
66+
<my-comp v-slot="{ childState }">
67+
{{ parentMsg }} {{ childState }}
68+
</my-comp>
69+
```
70+
71+
The child, instead of providing no template, should now render the default slot*:
72+
73+
```html
74+
<!--
75+
in child template, render default slot while passing
76+
in necessary private state of child.
77+
-->
78+
<template>
79+
<slot :childState="childState" />
80+
</template>
81+
```
82+
83+
> * Note: In 3.x, slots can be rendered as the root with native [fragments](/guide/migration/fragments) support!

0 commit comments

Comments
 (0)