Skip to content

Commit a5ace44

Browse files
committed
Merge remote-tracking branch 'upstream/lang-ja' into feature/sidebar-config
* upstream/lang-ja: Migration > v-on-native-modifier-removed の翻訳を追従 (#251) Migration > Watch の翻訳を追従 (#250) Migration > Listeners Removed の翻訳を追従 (#248)
2 parents e1ef4c6 + 5c63b27 commit a5ace44

File tree

4 files changed

+164
-3
lines changed

4 files changed

+164
-3
lines changed

src/.vuepress/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const sidebar = {
193193
'/guide/migration/inline-template-attribute',
194194
'/guide/migration/key-attribute',
195195
'/guide/migration/keycode-modifiers',
196-
// '/guide/migration/listeners-removed',
196+
'/guide/migration/listeners-removed',
197197
// '/guide/migration/mount-changes',
198198
// '/guide/migration/props-data',
199199
'/guide/migration/props-default-this',
@@ -202,12 +202,12 @@ const sidebar = {
202202
'/guide/migration/suspense',
203203
'/guide/migration/transition',
204204
// '/guide/migration/transition-group',
205-
// '/guide/migration/v-on-native-modifier-removed',
205+
'/guide/migration/v-on-native-modifier-removed',
206206
'/guide/migration/v-model',
207207
'/guide/migration/v-if-v-for',
208208
'/guide/migration/v-bind',
209209
// '/guide/migration/vnode-lifecycle-events',
210-
// '/guide/migration/watch'
210+
'/guide/migration/watch'
211211
]
212212
},
213213
],
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: $listeners の削除
3+
badges:
4+
- breaking
5+
---
6+
7+
# `$listeners` の削除 <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## 概要
10+
11+
`$listeners` オブジェクトは Vue 3 で削除されました。イベントリスナは `$attrs` の一部になりました。
12+
13+
```javascript
14+
{
15+
text: 'this is an attribute',
16+
onClose: () => console.log('close Event triggered')
17+
}
18+
```
19+
20+
## 2.x での構文
21+
22+
Vue 2 では、コンポーネントに渡された属性は `this.$attrs` で、イベントリスナは `this.$listeners` でアクセスできます。
23+
`inheritAttrs: false` と組み合わせることで、開発者はこれらの属性やリスナを、ルート要素ではなく他の要素に適用することができます:
24+
25+
```html
26+
<template>
27+
<label>
28+
<input type="text" v-bind="$attrs" v-on="$listeners" />
29+
</label>
30+
</template>
31+
<script>
32+
export default {
33+
inheritAttrs: false
34+
}
35+
</script>
36+
```
37+
38+
## 3.x での構文
39+
40+
Vue 3 の仮想 DOM では、イベントリスナはプレフィックスに `on` がついた単なる属性になり、 `$attrs` オブジェクトの一部であるため、 `$listeners` は削除されました。
41+
42+
```vue
43+
<template>
44+
<label>
45+
<input type="text" v-bind="$attrs" />
46+
</label>
47+
</template>
48+
<script>
49+
export default {
50+
inheritAttrs: false
51+
}
52+
</script>
53+
```
54+
55+
もしこのコンポーネントが `id` 属性と `v-on:close` リスナを受け取った場合、 `$attrs` オブジェクトは次のようになります:
56+
57+
```javascript
58+
{
59+
id: 'my-input',
60+
onClose: () => console.log('close Event triggered')
61+
}
62+
```
63+
64+
## 移行の戦略
65+
66+
`$listeners` の使用をすべて削除します。
67+
68+
## 参照
69+
70+
- [関連する RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0031-attr-fallthrough.md)
71+
- [移行ガイド - `class``style` を含む `$attrs`](./attrs-includes-class-style.md)
72+
- [移行ガイド - Render 関数 API](./render-function-api.md)
73+
- [移行ガイド - 新しい Emits のオプション](./emits-option.md)
74+
- [移行ガイド - `.native` 修飾子の削除](./v-on-native-modifier-removed.md)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: v-on.native 修飾子の削除
3+
badges:
4+
- breaking
5+
---
6+
7+
# `v-on.native` 修飾子の削除 <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## 概要
10+
11+
`v-on``.native` 修飾子は削除されました。
12+
13+
## 2.x での構文
14+
15+
`v-on` でコンポーネントに渡されたイベントリスナは、デフォルトでは `this.$emit` でイベントを発行することでのみ発火されます。代わりにネイティブ DOM リスナを子コンポーネントのルート要素に追加するには、 `.native` 修飾子を使用できます:
16+
17+
```html
18+
<my-component
19+
v-on:close="handleComponentEvent"
20+
v-on:click.native="handleNativeClickEvent"
21+
/>
22+
```
23+
24+
## 3.x での構文
25+
26+
`v-on``.native` 修飾子は削除されました。同時に、 [新しい `emits` オプション](./emits-option.md) によって、子要素が実際に発行するイベントを定義できるようになりました。
27+
28+
その結果、 Vue は子コンポーネントの発行するイベントとして定義されて _いない_ すべてのイベントリスナを、子のルート要素のネイティブイベントリスナとして追加するようになりました(ただし `inheritAttrs: false` が子のオプションで設定されていない場合)。
29+
30+
```html
31+
<my-component
32+
v-on:close="handleComponentEvent"
33+
v-on:click="handleNativeClickEvent"
34+
/>
35+
```
36+
37+
`MyComponent.vue`
38+
39+
```html
40+
<script>
41+
export default {
42+
emits: ['close']
43+
}
44+
</script>
45+
```
46+
47+
## 移行の戦略
48+
49+
- `.native` 修飾子のすべてのインスタンスを削除します。
50+
- すべてのコンポーネントが、 `emits` オプションでイベントを記録するようにします。
51+
52+
## 参照
53+
54+
- [関連する RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0031-attr-fallthrough.md#v-on-listener-fallthrough)
55+
- [移行ガイド - 新しい Emits のオプション](./emits-option.md)
56+
- [移行ガイド - `$listeners` の削除](./listeners-removed.md)
57+
- [移行ガイド - Render 関数 API](./render-function-api.md)

src/guide/migration/watch.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: 配列の監視
3+
badges:
4+
- breaking
5+
---
6+
7+
# {{ $frontmatter.title }} <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
## 概要
10+
11+
- **破壊的変更**: 配列を監視している場合、コールバックは配列が置き換えられたときにのみ実行します。配列の変更で実行する必要がある場合は、 `deep` オプションを指定する必要があります。
12+
13+
## 3.x の構文
14+
15+
[`watch` オプション](/api/options-data.html#watch) を使って配列を監視する場合、コールバックは配列が置き換えられたときにのみ実行します。言い換えれば、 watch コールバックは配列の変更では実行されなくなります。配列の変更で実行するには、 `deep` オプションを指定する必要があります。
16+
17+
```js
18+
watch: {
19+
bookList: {
20+
handler(val, oldVal) {
21+
console.log('book list changed')
22+
},
23+
deep: true
24+
},
25+
}
26+
```
27+
28+
## 移行の戦略
29+
30+
配列の変更を監視することに依存している場合は、 `deep` プロパティを追加して、コールバックが正しく実行されるようにします。

0 commit comments

Comments
 (0)