-
Notifications
You must be signed in to change notification settings - Fork 87
Guide > Composition API > Introduction の翻訳を追従 #282
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
kazupon
merged 7 commits into
vuejs-jp:lang-ja
from
naokie:guide/composition-api-introduction
Apr 26, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f2381b
docs: clarify the usage of toRefs and toRef for optional props
naokie d42abf4
Update composition-api-introduction.md
naokie 8bbc8ab
docs: use local copies of images rather than external URLs
naokie 57398ee
fix: untranslated parts #199
naokie cdc1530
fix: translate 'composition api'
naokie cbd7f5c
fix: missing anchor link
naokie f250b76
fix: easy to understand japanese
naokie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# はじめに | ||
|
||
## なぜコンポジション API なのか? | ||
## なぜ Composition API なのか? | ||
|
||
::: tip Note | ||
ドキュメントでここまで到達しているならば、[Vue の基本](introduction.md)と[コンポーネントの作成](component-basics.md)の両方にすでに精通しているはずです。 | ||
|
@@ -18,7 +18,10 @@ Vue コンポーネントを作成するとその機能と結合されたイン | |
export default { | ||
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList }, | ||
props: { | ||
user: { type: String } | ||
user: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
data () { | ||
return { | ||
|
@@ -54,29 +57,29 @@ export default { | |
|
||
コンポーネントのオプション (`data`, `computed`, `methods`, `watch`) でまとめたロジックはたいていの場合は正しく動作します。しかし、コンポーネントがより大きくなれば、**論理的な関心事**のリストもまた大きくなります。これは、特に最初からコンポーネントを書いていない人々にとって、コンポーネントを読みづらく、理解しづらいものにするかもしれません。 | ||
|
||
 | ||
 | ||
|
||
**論理的な関心事** が色でグループ化されている大きなコンポーネントを示す例。 | ||
|
||
このような分離は、複雑なコンポーネントを理解してメンテナンスすることを難しくします。このオプションの分離は背景にある論理的な関心事をわかりづらくします。さらに、単一の論理的な関心事に取り組む場合、関連するコードのオプションブロックを何度も "ジャンプ" する必要があります。 | ||
|
||
同じ論理的な関心事に関連するコードを並べることができれば、より良くなるでしょう。そして、これはまさにコンポジション API が可能にします。 | ||
同じ論理的な関心事に関連するコードを並べることができれば、より良くなるでしょう。そして、これはまさに Composition API が可能にします。 | ||
|
||
## コンポジション API の基本 | ||
## Composition API の基本 | ||
|
||
これで**なぜこの方法**にたどり着くのかわかりました。コンポジション API の使用を開始するには、初めに実際に使用できる場所が必要です。Vue コンポーネントでは、この場所を `setup` と呼びます。 | ||
これで**なぜこの方法**にたどり着くのかわかりました。 Composition API の使用を開始するには、初めに実際に使用できる場所が必要です。Vue コンポーネントでは、この場所を `setup` と呼びます。 | ||
|
||
### `setup` コンポーネントオプション | ||
|
||
<VideoLesson href="https://www.vuemastery.com/courses/vue-3-essentials/setup-and-reactive-references" title="Vue Mastery で setup がどのように動作するのか学ぶ">Vue Mastery で setup に関する無料ビデオを視聴する</VideoLesson> | ||
|
||
新しい `setup` コンポーネントオプションは、コンポーネントが作成される前に `props` が解決されると実行され、コンポジション API のエントリポイントとして機能します。 | ||
新しい `setup` コンポーネントオプションは、コンポーネントが作成される前に `props` が解決されると実行され、 Composition API のエントリポイントとして機能します。 | ||
|
||
::: warning | ||
`setup` が実行されたときは、まだコンポーネントのインスタンスが作られないため、`setup` オプションの中では `this` を使用できません。これは `props` を除いて、コンポーネント内で宣言されているあらゆるプロパティ (**ローカルの state** や **computed プロパティ**、**methods**) にアクセスできないことを意味します。 | ||
::: | ||
|
||
`setup` オプションは `props` と[後で](composition-api-setup.html#arguments)紹介する `context` を受け付ける関数であるべきです。さらに、`setup` から返される全てのものは、コンポーネントの残りの要素 (computed プロパティ、methods、ライフサイクルフックなど) およびコンポーネントの template に公開されます。 | ||
`setup` オプションは `props` と[後で](composition-api-setup.html#引数)紹介する `context` を受け付ける関数であるべきです。さらに、`setup` から返される全てのものは、コンポーネントの残りの要素 (computed プロパティ、methods、ライフサイクルフックなど) およびコンポーネントの template に公開されます。 | ||
|
||
`setup` をコンポーネントに追加しましょう: | ||
|
||
|
@@ -86,7 +89,10 @@ export default { | |
export default { | ||
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList }, | ||
props: { | ||
user: { type: String } | ||
user: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
console.log(props) // { user: '' } | ||
|
@@ -155,10 +161,10 @@ console.log(counter.value) // 1 | |
|
||
 | ||
|
||
任意の値の周りにラッパーオブジェクトがあると、途中でリアクティブでなくなることがなく、アプリ全体に安全に渡すことができます。 | ||
どんな値でもラッパーオブジェクトを持つことで、途中でリアクティブでなくなることがなく、アプリ全体に安全に渡すことができます。 | ||
|
||
::: tip Note | ||
言い換えれば、`ref` は値への**リアクティブな参照**を作成します。 **参照**を操作するという概念はコンポジション API 全体で頻繁に使用されます。 | ||
言い換えれば、`ref` は値への**リアクティブな参照**を作成します。 **参照**を操作するという概念は Composition API 全体で頻繁に使用されます。 | ||
::: | ||
|
||
例に戻って、リアクティブな `repositories` 変数を作成しましょう: | ||
|
@@ -192,7 +198,10 @@ import { ref } from 'vue' | |
export default { | ||
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList }, | ||
props: { | ||
user: { type: String } | ||
user: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
setup (props) { | ||
const repositories = ref([]) | ||
|
@@ -233,7 +242,7 @@ export default { | |
|
||
### ライフサイクルフックを `setup` の中に登録する | ||
|
||
オプション API に比べてコンポジション API の機能を完全にするには、ライフサイクルフックを `setup` の中に登録する必要があります。これは Vue から提供されるいくつかの新しい関数のおかげで可能になりました。コンポジション API におけるライフサイクルフックはオプション API と同様の名称ですが、`on` というプレフィックスが付いています。例: `mounted` は `onMounted` のようになっています。 | ||
オプション API に比べて Composition API の機能を完全にするには、ライフサイクルフックを `setup` の中に登録する必要があります。これは Vue から提供されるいくつかの新しい関数のおかげで可能になりました。 Composition API におけるライフサイクルフックはオプション API と同様の名称ですが、`on` というプレフィックスが付いています。例: `mounted` は `onMounted` のようになっています。 | ||
|
||
それらの関数はコンポーネントによってフックが呼び出されるときに実行されるコールバックを受け付けます。 | ||
|
||
|
@@ -300,7 +309,7 @@ export default { | |
} | ||
``` | ||
|
||
`watch` についての詳細は、[詳細ガイド]() を参照してください。 | ||
`watch` についての詳細は、[詳細ガイド](reactivity-computed-watchers.md#watch) を参照してください。 | ||
|
||
**例に適用しましょう:** | ||
|
||
|
@@ -392,7 +401,7 @@ setup (props) { | |
} | ||
``` | ||
|
||
他の**論理的な関心事**にも同じことができますが、既に疑問があるかもしれません。- _これはコードを `setup` オプションに移動させて肥大させるだけではありませんか?_ そのため他の責務に移る前に、まず上記のコードをスタンドアロンな**コンポジション関数**に抽出します。 `useUserRepositories` の作成から始めましょう: | ||
他の**論理的な関心事**にも同じことができますが、既に疑問があるかもしれません。- _これはコードを `setup` オプションに移動させて肥大させるだけではありませんか?_ そのため他の責務に移る前に、まず上記のコードをスタンドアロンな**Composition 関数**に抽出します。 `useUserRepositories` の作成から始めましょう: | ||
|
||
```js | ||
// src/composables/useUserRepositories.js | ||
|
@@ -416,7 +425,7 @@ export default function useUserRepositories(user) { | |
} | ||
``` | ||
|
||
And then the searching functionality: | ||
それから検索機能も: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #199 で指摘されていた未翻訳部分です。 |
||
|
||
```js | ||
// src/composables/useRepositoryNameSearch.js | ||
|
@@ -449,7 +458,10 @@ import { toRefs } from 'vue' | |
export default { | ||
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList }, | ||
props: { | ||
user: { type: String } | ||
user: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
setup (props) { | ||
const { user } = toRefs(props) | ||
|
@@ -495,7 +507,10 @@ import useRepositoryFilters from '@/composables/useRepositoryFilters' | |
export default { | ||
components: { RepositoriesFilters, RepositoriesSortBy, RepositoriesList }, | ||
props: { | ||
user: { type: String } | ||
user: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const { user } = toRefs(props) | ||
|
@@ -528,4 +543,4 @@ export default { | |
|
||
これで完了です! | ||
|
||
コンポジション API の表面とできることについてほんの少し触れただけであることを覚えておいてください。より詳しく知りたい場合は、詳細ガイドを参照してください。 | ||
Composition API の表面とできることについてほんの少し触れただけであることを覚えておいてください。より詳しく知りたい場合は、詳細ガイドを参照してください。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
訳文ちょっと理解が難しく、原文を読んだ結果、再度訳してみました。