Skip to content

Migration > Mount Changes の翻訳を追従 #255

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 4 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@ const sidebar = {
'/guide/migration/key-attribute',
'/guide/migration/keycode-modifiers',
'/guide/migration/listeners-removed',
// '/guide/migration/mount-changes',
'/guide/migration/mount-changes',
// '/guide/migration/props-data',
'/guide/migration/props-default-this',
'/guide/migration/render-function-api',
'/guide/migration/slots-unification',
'/guide/migration/suspense',
'/guide/migration/transition',
// '/guide/migration/transition-group',
'/guide/migration/transition-group',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#254 で翻訳済みです。

'/guide/migration/v-on-native-modifier-removed',
'/guide/migration/v-model',
'/guide/migration/v-if-v-for',
'/guide/migration/v-bind',
// '/guide/migration/vnode-lifecycle-events',
'/guide/migration/vnode-lifecycle-events',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#253 で翻訳済みです。

'/guide/migration/watch'
]
},
Expand Down
94 changes: 94 additions & 0 deletions src/guide/migration/mount-changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: 'マウント API の変更'
badges:
- breaking
---

# 要素を置換しないアプリケーションのマウント <MigrationBadges :badges="$frontmatter.badges" />

## 概要

Vue 2.x では、 `template` を持つアプリケーションをマウントすると、レンダリングされたコンテンツがマウント先の要素を置き換えます。 Vue 3.x では、レンダリングされたアプリケーションは、子要素として追加され、要素の `innerHTML` を置き換えます。

## 2.x での構文

Vue 2.x では、 HTML 要素セレクタを `new Vue()` または `$mount` に渡します:

```js
new Vue({
el: '#app',
data() {
return {
message: 'Hello Vue!'
}
},
template: `
<div id="rendered">{{ message }}</div>
`
})

// または
const app = new Vue({
data() {
return {
message: 'Hello Vue!'
}
},
template: `
<div id="rendered">{{ message }}</div>
`
})

app.$mount('#app')
```

このアプリケーションを渡されたセレクタ (ここでは `id="app"`) を持つ `div` のあるページにマウントした場合:

```html
<body>
<div id="app">
Some app content
</div>
</body>
```

レンダリングされた結果は、上記の `div` がレンダリングされたアプリケーションのコンテンツと置き換えられます:

```html
<body>
<div id="rendered">Hello Vue!</div>
</body>
```

## 3.x での構文

Vue 3.x では、アプリケーションをマウントすると、レンダリングされたコンテンツが `mount` に渡した要素の `innerHTML` を置き換えます:

```js
const app = Vue.createApp({
data() {
return {
message: 'Hello Vue!'
}
},
template: `
<div id="rendered">{{ message }}</div>
`
})

app.mount('#app')
```

このアプリケーションを `id="app"` を持つ `div` のあるページにマウントすると、このようになります:

```html
<body>
<div id="app" data-v-app="">
<div id="rendered">Hello Vue!</div>
</div>
</body>
```

## 参照

- [`mount` API](/api/application-api.html#mount)