Skip to content

Commit 22efa7a

Browse files
authored
Merge branch 'lang-ja' into guide/migration/attrs-includes-class-style
2 parents e78c865 + 6a73c04 commit 22efa7a

File tree

8 files changed

+209
-17
lines changed

8 files changed

+209
-17
lines changed

src/.vuepress/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ const sidebar = {
115115
'migration/async-components',
116116
'migration/attribute-coercion',
117117
'migration/attrs-includes-class-style',
118+
'migration/children',
118119
'migration/custom-directives',
119120
'migration/custom-elements-interop',
120121
'migration/data-option',
122+
'migration/emits-option',
121123
'migration/events-api',
122124
'migration/filters',
123125
'migration/fragments',

src/guide/migration/array-refs.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export default {
2525
},
2626
methods: {
2727
setItemRef(el) {
28-
this.itemRefs.push(el)
28+
if (el) {
29+
this.itemRefs.push(el)
30+
}
2931
}
3032
},
3133
beforeUpdate() {
@@ -40,13 +42,15 @@ export default {
4042
コンポジション API を使う場合
4143

4244
```js
43-
import { ref, onBeforeUpdate, onUpdated } from 'vue'
45+
import { onBeforeUpdate, onUpdated } from 'vue'
4446

4547
export default {
4648
setup() {
4749
let itemRefs = []
4850
const setItemRef = el => {
49-
itemRefs.push(el)
51+
if (el) {
52+
itemRefs.push(el)
53+
}
5054
}
5155
onBeforeUpdate(() => {
5256
itemRefs = []
@@ -55,7 +59,6 @@ export default {
5559
console.log(itemRefs)
5660
})
5761
return {
58-
itemRefs,
5962
setItemRef
6063
}
6164
}

src/guide/migration/async-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const asyncPageWithOptions = defineAsyncComponent({
6666
loader: () => import('./NextPage.vue'),
6767
delay: 200,
6868
timeout: 3000,
69-
error: ErrorComponent,
70-
loading: LoadingComponent
69+
errorComponent: ErrorComponent,
70+
loadingComponent: LoadingComponent
7171
})
7272
```
7373

src/guide/migration/children.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
badges:
3+
- removed
4+
---
5+
6+
# $children <MigrationBadges :badges="$frontmatter.badges" />
7+
8+
## 概要
9+
10+
インスタンスプロパティの `$children` は、Vue 3.0 から削除され、サポートされなくなりました。
11+
12+
## 2.x の構文
13+
14+
2.x では、開発者は `this.$children` を使って、現在のインスタンスの直接の子コンポーネントにアクセスすることができました。
15+
16+
```vue
17+
<template>
18+
<div>
19+
<img alt="Vue logo" src="./assets/logo.png">
20+
<my-button>Change logo</my-button>
21+
</div>
22+
</template>
23+
24+
<script>
25+
import MyButton from './MyButton'
26+
27+
export default {
28+
components: {
29+
MyButton
30+
},
31+
mounted() {
32+
console.log(this.$children) // [VueComponent]
33+
}
34+
}
35+
</script>
36+
```
37+
38+
## 3.x の更新
39+
40+
3.x では、 `$children` プロパティが削除され、サポートされなくなりました。代わりに、もし子コンポーネントのインスタンスにアクセスする必要がある場合は、 [$refs](/guide/component-template-refs.html#template-refs) を使用することをお勧めします。

src/guide/migration/custom-directives.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ badges:
77

88
## 概要
99

10-
変更点の概要は次のとおりです。
11-
12-
- API は、コンポーネントのライフサイクルとの整合性を高めるために名前が変更されました
13-
14-
詳細については、以下をお読みください。
10+
コンポーネントのライフサイクルに合わせて、ディレクティブのフック関数の名称が変更されました。
1511

1612
## 2.x の文法
1713

@@ -44,6 +40,7 @@ Vue.directive('highlight', {
4440

4541
ただし、Vue 3 では、カスタムディレクティブ用のよりまとまりのある API を作成しました。Vue 2 では、似たようなイベントにフックしているにもかかわらず、コンポーネントのライフサイクルメソッドとは大きく異なります。これらを次のように統合しました。
4642

43+
- **created** - 追加されました! これは、要素の属性やイベントリスナーが適用される前に呼び出されます。
4744
- bind → **beforeMount**
4845
- inserted → **mounted**
4946
- **beforeUpdate**: 追加されました! これは、コンポーネントのライフサイクルフックのように、要素自体が更新される前に呼び出されます。
@@ -58,7 +55,7 @@ Vue.directive('highlight', {
5855
const MyDirective = {
5956
beforeMount(el, binding, vnode, prevVnode) {},
6057
mounted() {},
61-
beforeUpdate() {},
58+
beforeUpdate() {}, // 追加
6259
updated() {},
6360
beforeUnmount() {}, // 追加
6461
unmounted() {}
@@ -104,5 +101,5 @@ mounted(el, binding, vnode) {
104101
```
105102

106103
:::warning
107-
[fragments](/guide/migration/fragments.html#overview) のサポートにより、コンポーネントは複数のルートノードを持つ可能性があります。マルチルートコンポーネントに適用すると、ディレクティブは無視され、警告がスローされます
108-
:::
104+
[fragments](/guide/migration/fragments.html#overview) のサポートにより、コンポーネントは複数のルートノードを持つ可能性があります。マルチルートコンポーネントに適用すると、ディレクティブは無視され、警告がログ出力されます
105+
:::

src/guide/migration/custom-elements-interop.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ badges:
77

88
## 概要
99

10-
- **BREAKING:** カスタム要素のホワイトリスト化はテンプレートのコンパイル中に実行されるようになりました。そのためランタイム設定ではなくコンパイラオプションで設定する必要があります。
10+
- **BREAKING:** タグをカスタム要素として扱うかのチェックは、テンプレートのコンパイル中に実行されるようになりました。そのためランタイム設定ではなくコンパイラオプションで設定する必要があります。
1111
- **BREAKING:** 特別な `is` プロパティの使用は予約済みの `<component>` タグのみに制限されます。
1212
- **NEW:** 新しい `v-is` ディレクティブが追加され、ネイティブ HTML のパース制限を回避するためにネイティブ要素で `is` が使用されていた 2.x のユースケースをサポートするようになりました。
1313

@@ -21,7 +21,7 @@ Vue の外部で定義されたカスタム要素を追加したい場合(例
2121

2222
### 2.x での構文
2323

24-
Vue 2.x では、カスタム要素としてのタグのホワイトリスト化は `Vue.config.ignoredElements` で行われていました
24+
Vue 2.x では、カスタム要素としてタグを設定するには `Vue.config.ignoredElements` を使用していました
2525

2626
```js
2727
// 以下で Vue は Vue の外部で定義されたカスタム要素を無視するようになります

src/guide/migration/data-option.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ badges:
88

99
## 概要
1010

11-
`data` コンポーネントオプション宣言はプレーンな JavaScript `object` を受け入れず、`function` 宣言を期待します。
11+
- **非互換**: `data` コンポーネントオプション宣言はプレーンな JavaScript `object` を受け入れず、`function` 宣言を期待します。
12+
13+
- **非互換**: ミックスインや継承で複数の `data` 返り値をマージする場合、マージはディープではなくシャローになりました(ルートレベルのプロパティのみマージされます)。
1214

1315
## 2.x での構文
1416

@@ -60,9 +62,60 @@ badges:
6062
</script>
6163
```
6264

65+
## ミックスインをマージする挙動の変更
66+
67+
このほか、コンポーネントとそのミックスインや継承元の `data()` がマージされる際に、マージは*シャロー*で行われるようになりました。
68+
69+
```js
70+
const Mixin = {
71+
data() {
72+
return {
73+
user: {
74+
name: 'Jack',
75+
id: 1
76+
}
77+
}
78+
}
79+
}
80+
81+
const CompA = {
82+
mixins: [Mixin],
83+
data() {
84+
return {
85+
user: {
86+
id: 2
87+
}
88+
}
89+
}
90+
}
91+
```
92+
93+
Vue 2.x での `$data` の結果は:
94+
95+
```json
96+
{
97+
user: {
98+
id: 2,
99+
name: 'Jack'
100+
}
101+
}
102+
```
103+
104+
3.0 では、このような結果に:
105+
106+
```json
107+
{
108+
user: {
109+
id: 2
110+
}
111+
}
112+
```
113+
63114
## 移行の戦略
64115

65116
オブジェクト宣言を利用しているユーザーには以下を推奨します:
66117

67118
- 共有データを外部オブジェクトとして抽出し、それを `data` のプロパティとして使う
68119
- 共有データへの参照、新しい共有オブジェクトを指すようにを書き換える
120+
121+
ミックスインのディープマージに依存しているユーザーには、そのような依存を完全に避けるためにコードをリファクタリングすることをお勧めします。ミックスインのディープマージは非常に暗黙的であり、コードロジックの理解やデバッグがより難しくなる可能性があります。
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: emits オプション
3+
badges:
4+
- new
5+
---
6+
7+
# `emits` オプション <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## 概要
10+
11+
Vue 3 では `emits` オプションが、既存の `props` オプションと同様に提供されるようになりました。このオプションを使用して、コンポーネントが親に発行できるイベントを定義することができます。
12+
13+
## 2.x の挙動
14+
15+
Vue 2 では、コンポーネントが受け取るプロパティを定義することはできますが、コンポーネントが発行できるイベントを宣言することはできません。
16+
17+
```vue
18+
<template>
19+
<div>
20+
<p>{{ text }}</p>
21+
<button v-on:click="$emit('accepted')">OK</button>
22+
</div>
23+
</template>
24+
<script>
25+
export default {
26+
props: ['text']
27+
}
28+
</script>
29+
```
30+
31+
## 3.x の挙動
32+
33+
プロパティと同様に、コンポーネントが発行するイベントは `emits` オプションで定義できるようになりました。
34+
35+
```vue
36+
<template>
37+
<div>
38+
<p>{{ text }}</p>
39+
<button v-on:click="$emit('accepted')">OK</button>
40+
</div>
41+
</template>
42+
<script>
43+
export default {
44+
props: ['text'],
45+
emits: ['accepted']
46+
}
47+
</script>
48+
```
49+
50+
このオプションはオブジェクトも受け取ります。これにより開発者は、発行されたイベントと一緒に渡される引数のバリデータを `props` 定義のバリデータと同様に定義できます。
51+
52+
詳細については、[この機能の API ドキュメント](../../api/options-data.md#emits)をお読みください。
53+
54+
## 移行方針
55+
56+
各コンポーネントから発行されたすべてのイベントを、 `emits` を使って発行することを強くお勧めします。
57+
58+
これは [`.native` 修飾子の削除](./v-on-native-modifier-removed.md) のために特に重要です。 `emits` で宣言されていないイベントのリスナーは、コンポーネントの `$attrs` に含まれるようになり、デフォルトではコンポーネントのルートノードに束縛されます。
59+
60+
###
61+
62+
ネイティブイベントを親に再発行するコンポーネントでは、これにより2つのイベントが発火することになります。
63+
64+
```vue
65+
<template>
66+
<button v-on:click="$emit('click', $event)">OK</button>
67+
</template>
68+
<script>
69+
export default {
70+
emits: [] // 宣言されていないイベント
71+
}
72+
</script>
73+
```
74+
75+
親がコンポーネントの `click` イベントをリッスンする場合:
76+
77+
```html
78+
<my-button v-on:click="handleClick"></my-button>
79+
```
80+
81+
これは _2回_ 引き起こされます。
82+
83+
- `$emit()` から一度。
84+
- ルート要素に適用されたネイティブイベントリスナから一度。
85+
86+
ここでは2つの選択肢があります。
87+
88+
1. `click` イベントを適切に宣言する。これは `<my-button>` のイベントハンドラに何らかのロジックを実際に追加する場合で役立ちます。
89+
2. `.native` を追加しなくても、親は簡単にネイティブイベントをリッスンできるので、イベントの再発行を削除します。とにかく明らかにイベントを再発行するだけの場合に適しています。
90+
91+
## 関連情報
92+
93+
- [関連する RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md)
94+
- [移行ガイド - `.native` 修飾子の削除](./v-on-native-modifier-removed.md)
95+
- [移行ガイド - `$listeners` の削除](./listeners-removed.md)
96+
- [移行ガイド - `class``style` を含む `$attrs`](./attrs-includes-class-style.md)
97+
- [移行ガイド - Render 関数 API の変更](./render-function-api.md)

0 commit comments

Comments
 (0)