-
Notifications
You must be signed in to change notification settings - Fork 5k
docs (#156): add inline-template attribute docs to migration guide #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bfbd964
docs (#156): add inline-template attribute docs to migration guide
bencodezen 403968e
docs (#156): add escape hatch
bencodezen 3d50093
docs (#156): improve syntax rendering
bencodezen 1fe67c6
Merge branch 'master' into docs/156-inline-template-removal
bencodezen 6267dcd
Merge branch 'master' into docs/156-inline-template-removal
bencodezen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| types: | ||
| - breaking | ||
| - removal | ||
| --- | ||
|
|
||
| # Inline Template Attribute | ||
|
|
||
| ## Overview | ||
|
|
||
| Support for the [inline-template feature](https://vuejs.org/v2/guide/components-edge-cases.html#Inline-Templates) has been removed. | ||
|
|
||
| ## 2.x Syntax | ||
|
|
||
| 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. | ||
|
|
||
| ```html | ||
| <my-component inline-template> | ||
| <div> | ||
| <p>These are compiled as the component's own template.</p> | ||
| <p>Not parent's transclusion content.</p> | ||
| </div> | ||
| </my-component> | ||
| ``` | ||
|
|
||
| ## 3.x Syntax | ||
|
|
||
| This feature will no longer be supported. | ||
|
|
||
| ## Migration Strategy | ||
|
|
||
| Most of the use cases for `inline-template` assumes a no-build-tool setup, where all templates are written directly inside the HTML page. | ||
|
|
||
| ### Option #1: Use `<script>` tag | ||
|
|
||
| The most straightforward workaround in such cases is using `<script>` with an alternative type: | ||
|
|
||
| ```js | ||
| <script type="text/html" id="my-comp-template"> | ||
| <div>{{ hello }}</div> | ||
| </script> | ||
| ``` | ||
|
|
||
| And in the component, target the template using a selector: | ||
|
|
||
| ```js | ||
| const MyComp = { | ||
| template: '#my-comp-template' | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ### Option #2: Default Slot | ||
|
|
||
| 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: | ||
|
|
||
| ```html | ||
| <!-- 2.x Syntax --> | ||
| <my-comp inline-template :msg="parentMsg"> | ||
| {{ msg }} {{ childState }} | ||
| </my-comp> | ||
|
|
||
| <!-- Default Slot Version --> | ||
| <my-comp v-slot="{ childState }"> | ||
| {{ parentMsg }} {{ childState }} | ||
| </my-comp> | ||
| ``` | ||
|
|
||
| The child, instead of providing no template, should now render the default slot\*: | ||
|
|
||
| ```html | ||
| <!-- | ||
| in child template, render default slot while passing | ||
| in necessary private state of child. | ||
| --> | ||
| <template> | ||
| <slot :childState="childState" /> | ||
| </template> | ||
| ``` | ||
|
|
||
| \* Note: In 3.x, slots can be rendered as the root with native [fragments](/guide/migration/fragments) support! | ||
bencodezen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.