Skip to content

Commit 9aac71b

Browse files
authored
Advanced Guides > Compotion API > Template Refs の翻訳 (#93)
* translate composition-api-template-refs * [FIX] 訳し方を変更 * [FIX] レビュー内容を反映して日本語訳を修正
1 parent 2e590dd commit 9aac71b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/guide/composition-api-template-refs.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## Template Refs
1+
## テンプレート参照
22

3-
> This section uses [single-file component](single-file-component.html) syntax for code examples
3+
> この節ではコード例で [単一ファイルコンポーネント](single-file-component.html)の文法を使用しています。
44
5-
> This guide assumes that you have already read the [Composition API Introduction](composition-api-introduction.html) and [Reactivity Fundamentals](reactivity-fundamentals.html). Read that first if you are new to Composition API.
5+
> このガイドはすでに [コンポジション API 導入](composition-api-introduction.html) を読んでいることを前提に書かれています。もしまだ読んでいないのなら、先に読みましょう。
66
7-
When using the Composition API, the concept of [reactive refs](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs) and [template refs](component-template-refs.html) are unified. In order to obtain a reference to an in-template element or component instance, we can declare a ref as usual and return it from [setup()](composition-api-setup.html):
7+
コンポジション API を使うとき、 [リアクティブ参照](reactivity-fundamentals.html#creating-standalone-reactive-values-as-refs)[テンプレート参照](component-template-refs.html) のコンセプトは同じになります。
8+
テンプレート内の要素やコンポーネントインスタンスの参照を取得するために、 ref 変数を定義して [setup()](composition-api-setup.html) で返します。
89

910
```html
1011
<template>
@@ -19,7 +20,7 @@ When using the Composition API, the concept of [reactive refs](reactivity-fundam
1920
const root = ref(null)
2021
2122
onMounted(() => {
22-
// the DOM element will be assigned to the ref after initial render
23+
// DOM 要素は初期描画の後に ref に代入されます
2324
console.log(root.value) // <div>This is a root element</div>
2425
})
2526
@@ -31,9 +32,9 @@ When using the Composition API, the concept of [reactive refs](reactivity-fundam
3132
</script>
3233
```
3334

34-
Here we are exposing `root` on the render context and binding it to the div as its ref via `ref="root"`. In the Virtual DOM patching algorithm, if a VNode's `ref` key corresponds to a ref on the render context, the VNode's corresponding element or component instance will be assigned to the value of that ref. This is performed during the Virtual DOM mount / patch process, so template refs will only get assigned values after the initial render.
35+
描画コンテキストに `root` 変数を渡していて、`ref="root"` 経由で div 要素と束縛します。 仮想 DOM のパッチアルゴリズムの中で、 もし VNode`ref` キーは描画コンテキストの ref に対応すると、VNode の対応する要素またはコンポーネントインスタンスに ref の値が割り当てられます。これは仮想 DOM のマウント/パッチ処理中に実行されるので、テンプレート refs では初期描画に値だけを取得できます。
3536

36-
Refs used as templates refs behave just like any other refs: they are reactive and can be passed into (or returned from) composition functions.
37+
テンプレート参照は他の参照と似た挙動をします。つまり、リアクティブかつコンポジション関数に渡せる(または返せる)ことができます。
3738

3839
### Usage with JSX
3940

@@ -47,15 +48,15 @@ export default {
4748
ref: root
4849
})
4950

50-
// with JSX
51+
// JSX 記法
5152
return () => <div ref={root} />
5253
}
5354
}
5455
```
5556

5657
### Usage inside `v-for`
5758

58-
Composition API template refs do not have special handling when used inside `v-for`. Instead, use function refs to perform custom handling:
59+
コンポジション API のテンプレート参照を `v-for` 内部で使う時には特別な処理はされないです。代わりに、参照を提供する関数を使って独自処理を実行してください。
5960

6061
```html
6162
<template>
@@ -72,7 +73,7 @@ Composition API template refs do not have special handling when used inside `v-f
7273
const list = reactive([1, 2, 3])
7374
const divs = ref([])
7475
75-
// make sure to reset the refs before each update
76+
// 忘れずにアップデート前に ref をリセットしてください
7677
onBeforeUpdate(() => {
7778
divs.value = []
7879
})

0 commit comments

Comments
 (0)