Skip to content

Commit 3147cc5

Browse files
Mention application mounting changes in migration guide and API (#936)
* feat: added mount API changes page * fix: added changes to mount API * fix: fixed a template API * fix: fixed svg diagram * fix: changed a wording * fix: fixed svg * fix: mention template * fix: fixed a wording on application API * Update src/guide/migration/introduction.md Co-authored-by: Thorsten Lünborg <[email protected]> * Update src/guide/migration/mount-changes.md Co-authored-by: Thorsten Lünborg <[email protected]> * Update src/guide/migration/mount-changes.md Co-authored-by: Thorsten Lünborg <[email protected]> * Update src/guide/migration/mount-changes.md Co-authored-by: Thorsten Lünborg <[email protected]> Co-authored-by: Thorsten Lünborg <[email protected]>
1 parent 2106042 commit 3147cc5

File tree

6 files changed

+101
-6
lines changed

6 files changed

+101
-6
lines changed

src/.vuepress/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const sidebar = {
194194
'/guide/migration/key-attribute',
195195
'/guide/migration/keycode-modifiers',
196196
'/guide/migration/listeners-removed',
197+
'/guide/migration/mount-changes',
197198
'/guide/migration/props-data',
198199
'/guide/migration/props-default-this',
199200
'/guide/migration/render-function-api',

src/.vuepress/public/images/lifecycle.svg

+2-2
Loading

src/api/application-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Apart from `el`, you should treat these arguments as read-only and never modify
191191

192192
- **Usage:**
193193

194-
Mounts a root component of the application instance on the provided DOM element.
194+
The `innerHTML` of the provided DOM element will be replaced with the rendered template of the application root component.
195195

196196
- **Example:**
197197

src/api/options-dom.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- **Details:**
88

9-
A string template to be used as the markup for the component instance. The template will **replace** the mounted element. Any existing markup inside the mounted element will be ignored, unless content distribution slots are present in the template.
9+
A string template to be used as the markup for the component instance. The template will **replace** the `innerHTML` of mounted element. Any existing markup inside the mounted element will be ignored, unless content distribution slots are present in the template.
1010

1111
If the string starts with `#` it will be used as a `querySelector` and use the selected element's innerHTML as the template string. This allows the use of the common `<script type="x-template">` trick to include templates.
1212

src/guide/migration/introduction.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ The following consists a list of breaking changes from 2.x:
105105
- [`<TransitionGroup>` now renders no wrapper element by default](/guide/migration/transition-group.html)
106106
- [When watching an array, the callback will only trigger when the array is replaced. If you need to trigger on mutation, the `deep` option must be specified.](/guide/migration/watch.html)
107107
- `<template>` tags with no special directives (`v-if/else-if/else`, `v-for`, or `v-slot`) are now treated as plain elements and will result in a native `<template>` element instead of rendering its inner content.
108-
- In Vue 2.x, application root container's `outerHTML` is replaced with root component template (or eventually compiled to a template, if root component has no template/render option). Vue 3.x now uses application container's `innerHTML` instead - this means the container itself is no longer considered part of the template.
108+
- [Mounted application does not replace the element it's mounted to](/guide/migration/mount-changes.html)
109109
- [Lifecycle `hook:` events prefix changed to `vnode-`](/guide/migration/vnode-lifecycle-events.html)
110110

111111
### Removed APIs
112112

113113
- [`keyCode` support as `v-on` modifiers](/guide/migration/keycode-modifiers.html)
114-
- [$on, $off and $once instance methods](/guide/migration/events-api.html)
114+
- [$on, $off and \$once instance methods](/guide/migration/events-api.html)
115115
- [Filters](/guide/migration/filters.html)
116116
- [Inline templates attributes](/guide/migration/inline-template-attribute.html)
117117
- [`$children` instance property](/guide/migration/children.html)

src/guide/migration/mount-changes.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: 'Mount API changes'
3+
badges:
4+
- breaking
5+
---
6+
7+
# Mounted application does not replace the element <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## Overview
10+
11+
In Vue 2.x, when mounting an application that has a `template`, the rendered content replaces the element we mount to. In Vue 3.x, the rendered application is appended as a child of such an element, replacing element's `innerHTML`.
12+
13+
## 2.x Syntax
14+
15+
In Vue 2.x, we pass an HTML element selector to `new Vue()` or `$mount`:
16+
17+
```js
18+
new Vue({
19+
el: '#app',
20+
data() {
21+
return {
22+
message: 'Hello Vue!'
23+
}
24+
},
25+
template: `
26+
<div id="rendered">{{ message }}</div
27+
`
28+
})
29+
30+
// or
31+
const app = new Vue({
32+
data() {
33+
return {
34+
message: 'Hello Vue!'
35+
}
36+
},
37+
template: `
38+
<div id="rendered">{{ message }}</div
39+
`
40+
})
41+
42+
app.$mount('#app')
43+
```
44+
45+
When we mount this application to the page that has a `div` with the passed selector (in our case, it's `id="app"`):
46+
47+
```html
48+
<body>
49+
<div id="app">
50+
Some app content
51+
</div>
52+
</body>
53+
```
54+
55+
in the rendered result, the mentioned `div` will be replaced with the rendered application content:
56+
57+
```html
58+
<body>
59+
<div id="rendered">Hello Vue!</div>
60+
</body>
61+
```
62+
63+
## 3.x Syntax
64+
65+
In Vue 3.x, when we mount an application, its rendered content will replace the `innerHTML` of the element we pass to `mount`:
66+
67+
```js
68+
const app = Vue.createApp({
69+
data() {
70+
return {
71+
message: 'Hello Vue!'
72+
}
73+
},
74+
template: `
75+
<div id="rendered">{{ message }}</div>
76+
`
77+
})
78+
79+
app.mount('#app')
80+
```
81+
82+
When this app is mounted to the page that has a `div` with `id="app"`, this will result in:
83+
84+
```html
85+
<body>
86+
<div id="app" data-v-app="">
87+
<div id="rendered">Hello Vue!</div>
88+
</div>
89+
</body>
90+
```
91+
92+
## See also
93+
94+
- [`mount` API](/api/application-api.html#mount)

0 commit comments

Comments
 (0)