Skip to content

Commit cf116b4

Browse files
committed
Merge branch 'lang-ja' into translate-data-option
2 parents 9f89571 + 90d5a7c commit cf116b4

11 files changed

+585
-263
lines changed

src/.vuepress/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const sidebar = {
111111
collapsable: true,
112112
children: [
113113
'migration/introduction',
114+
'migration/array-refs',
114115
'migration/async-components',
115116
'migration/attribute-coercion',
116117
'migration/custom-directives',
@@ -127,7 +128,8 @@ const sidebar = {
127128
'migration/render-function-api',
128129
'migration/slots-unification',
129130
'migration/transition',
130-
'migration/v-model'
131+
'migration/v-model',
132+
'migration/v-bind'
131133
]
132134
},
133135
{

src/guide/migration/array-refs.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: v-forのref配列
3+
badges:
4+
- breaking
5+
---
6+
7+
# {{ $frontmatter.title }} <MigrationBadges :badges="$frontmatter.badges" />
8+
9+
Vue 2 では、`v-for` の中で `ref` 属性を記述すると、対応する `$refs` プロパティに参照の配列を入れます。この動作は、入れ子になった `v-for` がある場合、曖昧で非効率的になります。
10+
11+
Vue 3 では、この記述では `$refs` に配列が作成されなくなりました。1つのバインディングから複数の参照を取得するには、関数に `ref` をバインドします (これは新機能です)。
12+
13+
```html
14+
<div v-for="item in list" :ref="setItemRef"></div>
15+
```
16+
17+
オプション API を使う場合
18+
19+
```js
20+
export default {
21+
data() {
22+
return {
23+
itemRefs: []
24+
}
25+
},
26+
methods: {
27+
setItemRef(el) {
28+
this.itemRefs.push(el)
29+
}
30+
},
31+
beforeUpdate() {
32+
this.itemRefs = []
33+
},
34+
updated() {
35+
console.log(this.itemRefs)
36+
}
37+
}
38+
```
39+
40+
コンポジション API を使う場合
41+
42+
```js
43+
import { ref, onBeforeUpdate, onUpdated } from 'vue'
44+
45+
export default {
46+
setup() {
47+
let itemRefs = []
48+
const setItemRef = el => {
49+
itemRefs.push(el)
50+
}
51+
onBeforeUpdate(() => {
52+
itemRefs = []
53+
})
54+
onUpdated(() => {
55+
console.log(itemRefs)
56+
})
57+
return {
58+
itemRefs,
59+
setItemRef
60+
}
61+
}
62+
}
63+
```
64+
65+
注意点
66+
67+
- `itemRefs` は配列である必要はありません。 反復キーで参照できるオブジェクトでも構いません。
68+
69+
- これにより、必要に応じて `itemRefs` をリアクティブにして監視することもできます。

src/guide/migration/async-components.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ badges:
33
- new
44
---
55

6-
# Async Components <MigrationBadges :badges="$frontmatter.badges" />
6+
# 非同期コンポーネント <MigrationBadges :badges="$frontmatter.badges" />
77

8-
## Overview
8+
## 概要
99

10-
Here is a high level overview of what has changed:
10+
こちらが大まかな変更の概要です:
1111

12-
- New `defineAsyncComponent` helper method that explicitly defines async components
13-
- `component` option renamed to `loader`
14-
- Loader function does not inherently receive `resolve` and `reject` arguments and must return a Promise
12+
- 明示的に非同期コンポーネントを定義する、新しい `defineAsyncComponent` ヘルパーメソッド
13+
- `component` オプションは `loader` に名前が替わりました
14+
- loader 関数は本質的に `resolve` `reject` を引数にとらず、必ず Promise を返却します
1515

16-
For a more in-depth explanation, read on!
16+
さらに詳しい説明のために読み進めましょう!
1717

18-
## Introduction
18+
## イントロダクション
1919

20-
Previously, async components were created by simply defining a component as a function that returned a promise, such as:
20+
以前、非同期コンポーネントは Promise を返す関数としてコンポーネントを定義することで、このように簡単に作成されました:
2121

2222
```js
2323
const asyncPage = () => import('./NextPage.vue')
2424
```
2525

26-
Or, for the more advanced component syntax with options:
26+
または、オプション付きのさらに高度なコンポーネント構文として:
2727

2828
```js
2929
const asyncPage = {
@@ -35,19 +35,19 @@ const asyncPage = {
3535
}
3636
```
3737

38-
## 3.x Syntax
38+
## 3.x での構文
3939

40-
Now, in Vue 3, since functional components are defined as pure functions, async components definitions need to be explicitly defined by wrapping it in a new `defineAsyncComponent` helper:
40+
現在、Vue 3 では、関数型コンポーネントは純粋関数として定義されるので、非同期コンポーネントは新しい `defineAsyncComponent` ヘルパーでラップして定義する必要があります:
4141

4242
```js
4343
import { defineAsyncComponent } from 'vue'
4444
import ErrorComponent from './components/ErrorComponent.vue'
4545
import LoadingComponent from './components/LoadingComponent.vue'
4646

47-
// Async component without options
47+
// オプションなしの非同期コンポーネント
4848
const asyncPage = defineAsyncComponent(() => import('./NextPage.vue'))
4949

50-
// Async component with options
50+
// オプション付きの非同期コンポーネント
5151
const asyncPageWithOptions = defineAsyncComponent({
5252
loader: () => import('./NextPage.vue'),
5353
delay: 200,
@@ -57,7 +57,7 @@ const asyncPageWithOptions = defineAsyncComponent({
5757
})
5858
```
5959

60-
Another change that has been made from 2.x is that the `component` option is now renamed to `loader` in order to accurately communicate that a component definition cannot be provided directly.
60+
2.x からなされたもう一つの変更は、直接コンポーネント定義を提供できないことを正確に伝えるために `component` オプションの名前が `loader` に替わったことです。
6161

6262
```js{4}
6363
import { defineAsyncComponent } from 'vue'
@@ -71,7 +71,7 @@ const asyncPageWithOptions = defineAsyncComponent({
7171
})
7272
```
7373

74-
In addition, unlike 2.x, the loader function no longer receives the `resolve` and `reject` arguments and must always return a Promise.
74+
加えて、2.x とは異なり、loader 関数はもう `resolve` `reject` を引数にとらず、常に Promise を返します。
7575

7676
```js
7777
// 2.x version
@@ -88,6 +88,6 @@ const asyncComponent = defineAsyncComponent(
8888
)
8989
```
9090

91-
For more information on the usage of async components, see:
91+
非同期コンポーネントの使い方のさらなる情報は、以下を見てください:
9292

93-
- [Guide: Dynamic & Async Components](/guide/component-dynamic-async.html#dynamic-components-with-keep-alive)
93+
- [ガイド: 動的 & 非同期コンポーネント](/guide/component-dynamic-async.html#動的コンポーネントにおける-keep-alive-の利用)

0 commit comments

Comments
 (0)