Skip to content

Commit 2e590dd

Browse files
resesshkazupon
andauthored
docs: Components In-Depth > Dynamic & Async Components の翻訳 (#90)
* translate component-dynamic-async * Update src/guide/component-dynamic-async.md Co-authored-by: kazuya kawaguchi <[email protected]> * Update src/guide/component-dynamic-async.md Co-authored-by: kazuya kawaguchi <[email protected]> * Update src/guide/component-dynamic-async.md Co-authored-by: kazuya kawaguchi <[email protected]> Co-authored-by: kazuya kawaguchi <[email protected]>
1 parent 0615ad0 commit 2e590dd

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/guide/component-dynamic-async.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Dynamic & Async Components
1+
# 動的 & 非同期コンポーネント
22

3-
> This page assumes you've already read the [Components Basics](component-basics.md). Read that first if you are new to components.
3+
> このページはすでに [コンポーネントの基本](component-basics.md) を読んでいる事を前提としています。コンポーネントをよく知らない方はそちらを先にお読みください。
44
5-
## Dynamic Components with `keep-alive`
5+
## 動的コンポーネントにおける `keep-alive` の利用
66

7-
Earlier, we used the `is` attribute to switch between components in a tabbed interface:
7+
まず、`is` 属性を利用してタブインタフェースのコンポーネントを切り替えることができます:
88

99
```vue-html
1010
<component :is="currentTabComponent"></component>
1111
```
1212

13-
When switching between these components though, you'll sometimes want to maintain their state or avoid re-rendering for performance reasons. For example, when expanding our tabbed interface a little:
13+
しかし、コンポーネントを切り替える時、コンポーネントの状態を保持したり、パフォーマンスの理由から再レンダリングを避けたいときもあるでしょう。例えば、タブインターフェースを少し拡張した場合:
1414

1515
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="jOPjZOe" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Dynamic components: without keep-alive">
1616
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/jOPjZOe">
@@ -19,18 +19,18 @@ When switching between these components though, you'll sometimes want to maintai
1919
</p>
2020
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
2121

22-
You'll notice that if you select a post, switch to the _Archive_ tab, then switch back to _Posts_, it's no longer showing the post you selected. That's because each time you switch to a new tab, Vue creates a new instance of the `currentTabComponent`.
22+
投稿を選択し、 _Archive_ タブに切り替えてから _Posts_ に戻ると、選択していた投稿は表示されなくなります。 これは、新しいタブに切り替えるたびに、Vue `currentTabComponent` の新しいインスタンスを作成するからです。
2323

24-
Recreating dynamic components is normally useful behavior, but in this case, we'd really like those tab component instances to be cached once they're created for the first time. To solve this problem, we can wrap our dynamic component with a `<keep-alive>` element:
24+
動的コンポーネントの再生成は通常は便利な挙動です。しかし、このケースでは最初に作成されたタブコンポーネントのインスタンスがキャッシュされるのが好ましいでしょう。この問題を解決するために、動的コンポーネントを `<keep-alive>` 要素でラップすることができます:
2525

2626
```vue-html
27-
<!-- Inactive components will be cached! -->
27+
<!-- アクティブでないコンポーネントはキャッシュされます! -->
2828
<keep-alive>
2929
<component :is="currentTabComponent"></component>
3030
</keep-alive>
3131
```
3232

33-
Check out the result below:
33+
以下の結果を確認してみてください:
3434

3535
<p class="codepen" data-height="300" data-theme-id="39028" data-default-tab="html,result" data-user="Vue" data-slug-hash="VwLJQvP" data-editable="true" style="height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;" data-pen-title="Dynamic components: with keep-alive">
3636
<span>See the Pen <a href="https://codepen.io/team/Vue/pen/VwLJQvP">
@@ -39,13 +39,13 @@ Check out the result below:
3939
</p>
4040
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
4141

42-
Now the _Posts_ tab maintains its state (the selected post) even when it's not rendered.
42+
このように _Posts_ タブがレンダリングされていなくても、自身の状態(選択された投稿)を保持するようになります。
4343

44-
Check out more details on `<keep-alive>` in the [API reference](../api/built-in-components.html#keep-alive).
44+
`<keep-alive>` の詳細な情報については [API リファレンス](../api/built-in-components.html#keep-alive) を参照してください。
4545

46-
## Async Components
46+
## 非同期コンポーネント
4747

48-
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a `defineAsyncComponent` method:
48+
大規模なアプリケーションでは、アプリケーションを小さなまとまりに分割し、必要なコンポーネントだけサーバーから読み込みたい場合があるでしょう。これを可能にするために、 Vue `defineAsyncComponent` メソッドを持ちます:
4949

5050
```js
5151
const app = Vue.createApp({})
@@ -62,9 +62,9 @@ const AsyncComp = Vue.defineAsyncComponent(
6262
app.component('async-example', AsyncComp)
6363
```
6464

65-
As you can see, this method accepts a factory function returning a `Promise`. Promise's `resolve` callback should be called when you have retrieved your component definition from the server. You can also call `reject(reason)` to indicate the load has failed.
65+
見て分かるとおり、このメソッドは `Promise` を返すファクトリ関数を受けます。サーバーからコンポーネント定義を取得したら Promise`resolve` コールバックが呼ばれるべきです。また、読み込みが失敗したことを示すために `reject(reason)` を呼ぶこともできます。
6666

67-
You can also return a `Promise` in the factory function, so with Webpack 2 or later and ES2015 syntax you can do:
67+
ファクトリ関数の中で `Promise` を返すことができるので、 Webpack 2 以降と ES2015 の構文では以下のように書くこともできます:
6868

6969
```js
7070
import { defineAsyncComponent } from 'vue'
@@ -76,7 +76,7 @@ const AsyncComp = defineAsyncComponent(() =>
7676
app.component('async-component', AsyncComp)
7777
```
7878

79-
You can also use `defineAsyncComponent` when [registering a component locally](component-registration.html#local-registration):
79+
[コンポーネントのローカル登録](component-registration.html#local-registration) でも、 `defineAsyncComponent` を利用することができます。
8080

8181
```js
8282
import { createApp, defineAsyncComponent } from 'vue'
@@ -91,10 +91,10 @@ createApp({
9191
})
9292
```
9393

94-
### Using with Suspense
94+
### Suspense との併用
9595

96-
Async components are _suspensible_ by default. This means if it has a [`<Suspense>`](TODO) in the parent chain, it will be treated as an async dependency of that `<Suspense>`. In this case, the loading state will be controlled by the `<Suspense>`, and the component's own loading, error, delay and timeout options will be ignored.
96+
非同期コンポーネントはデフォルトで _suspensible_ です。これは非同期コンポーネントが [`<Suspense>`](TODO) を親に持ったとき、 `<Suspense>` の非同期の依存として取り扱われることを意味しています。このケースでは、読み込みの状態は `<Suspense>` から制御され、コンポーネント自身が持つ loadingerror, delay, timeout といったオプションは無視されます。
9797

98-
The async component can opt-out of `Suspense` control and let the component always control its own loading state by specifying `suspensible: false` in its options.
98+
非同期コンポーネントのオプションに `suspensible: false` を指定することで、 `Suspense` の制御から外すことができ、常にコンポーネントが自身の読み込み状態を制御することができます。
9999

100-
You can check the list of available options in the [API Reference](../api/global-api.html#arguments-4)
100+
[API リファレンス](../api/global-api.html#arguments-4) で利用可能なオプションのリストを確認できます。

0 commit comments

Comments
 (0)