Skip to content

Commit 77e4437

Browse files
committed
update
1 parent 8b16dda commit 77e4437

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/guide/component-attrs.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
# Non-Prop Attributes
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
55
A component non-prop attribute is an attribute or event listener that is passed to a component, but does not have a corresponding property defined in [props](component-props) or [emits](component-custom-events.html#defining-custom-events). Common examples of this include `class`, `style`, and `id` attributes.
66

7-
## Attribute Inheritance
7+
コンポーネントにおけるプロパティでない属性とは、コンポーネントに渡される属性やイベントリスナのうち、[props](component-props)[emits](component-custom-events.html#defining-custom-events) で定義されたものを除いたものをいいます。なお、共通の認識として `class``style`, `id` 属性はここに含まれません。
8+
9+
10+
## 属性の継承
11+
12+
ただ一つのルート要素をもつコンポーネントの場合、プロパティでない属性はルート要素にそのまま追加されます。例えば date-picker コンポーネントの場合は次のような形になります。
813

9-
When a component returns a single root node, non-prop attributes will automatically be added to the root node's attributes. For example, in the instance of a date-picker component:
1014

1115
```js
1216
app.component('date-picker', {
@@ -18,19 +22,19 @@ app.component('date-picker', {
1822
})
1923
```
2024

21-
In the event we need to define the status of the date-picker component via a `data-status` property, it will be applied to the root node (i.e., `div.date-picker`).
25+
`data-status` プロパティを用いて date-picker コンポーネントの状態を定義するような場合には、このプロパティはルート要素 (すなわち `div.date-picker`) に適用されます。
2226

2327
```html
24-
<!-- Date-picker component with a non-prop attribute -->
28+
<!-- 非プロパティ型の属性 とともに用いられる Date-picker コンポーネント -->
2529
<date-picker data-status="activated"></date-picker>
2630

27-
<!-- Rendered date-picker component -->
31+
<!-- 実際には以下のような形で描画されます -->
2832
<div class="date-picker" data-status="activated">
2933
<input type="datetime" />
3034
</div>
3135
```
3236

33-
Same rule applies to the event listeners:
37+
イベントリスナについても同様のことが言えます。
3438

3539
```html
3640
<date-picker @change="submitChange"></date-picker>
@@ -44,7 +48,7 @@ app.component('date-picker', {
4448
})
4549
```
4650

47-
This might be helpful when we have an HTML element with `change` event as a root element of `date-picker`.
51+
このような実装は、`date-picker` のルート要素で `change` イベントを扱うケースなどで役に立つでしょう。
4852

4953
```js
5054
app.component('date-picker', {
@@ -58,7 +62,7 @@ app.component('date-picker', {
5862
})
5963
```
6064

61-
In this case, `change` event listener is passed from the parent component to the child and it will be triggered on native `<select>` `change` event. We won't need to emit an event from the `date-picker` explicitly:
65+
この場合、 `change` イベントリスナは、親から子へ渡され、`<select>` 要素本来の `change` イベントにより発火されます。特段、`date-picker` からの明示的なイベント処理を記述する必要はありません。
6266

6367
```html
6468
<div id="date-picker" class="demo">
@@ -70,21 +74,20 @@ In this case, `change` event listener is passed from the parent component to the
7074
const app = Vue.createApp({
7175
methods: {
7276
showChange(event) {
73-
console.log(event.target.value) // will log a value of the selected option
77+
console.log(event.target.value) // 選択された option の値が表示される
7478
}
7579
}
7680
})
7781
```
7882

7983
## Disabling Attribute Inheritance
8084

81-
If you do **not** want a component to automatically inherit attributes, you can set `inheritAttrs: false` in the component's options.
82-
83-
The common scenario for disabling an attribute inheritance is when attributes need to be applied to other elements besides the root node.
85+
属性の継承を望まない場合、コンポーネントのオプション内で、`inheritAttrs: false`を指定することができます。
8486

85-
By setting the `inheritAttrs` option to `false`, this gives you access to the component's `$attrs` property, which includes all attributes not included to component `props` and `emits` properties (e.g., `class`, `style`, `v-on` listeners, etc.).
87+
一般的にこの継承を無効化したいケースというのは、ルート要素ではない別の要素に属性を適用したいようなケースでしょう。
8688

87-
Using our date-picker component example from the [previous section]('#attribute-inheritance), in the event we need to apply all non-prop attributes to the `input` element rather than the root `div` element, this can be accomplished by using the `v-bind` shortcut.
89+
`inheritAttrs``false` にセットすることで、コンポーネントの `$attrs` プロパティが利用可能になり、`props``emits` などのプロパティ(`class``style``v-on` といったもの)を除く全ての属性にアクセスできるようになります。
90+
[previous section]('#属性の継承) で利用した date-picker のコンポーネント例で、全てのプロパティでない属性を ルートの `div` 要素ではなく `input` 要素に適用する場合には、`v-bind` を用いると便利でしょう。
8891

8992
```js{5}
9093
app.component('date-picker', {
@@ -97,7 +100,7 @@ app.component('date-picker', {
97100
})
98101
```
99102

100-
With this new configuration, our `data-status` attribute will be applied to our `input` element!
103+
このように記述した場合、`data-status` 属性は、 `input` 要素に適用されます。
101104

102105
```html
103106
<!-- Date-picker component with a non-prop attribute -->
@@ -111,14 +114,14 @@ With this new configuration, our `data-status` attribute will be applied to our
111114

112115
## Attribute Inheritance on Multiple Root Nodes
113116

114-
Unlike single root node components, components with multiple root nodes do not have an automatic attribute fallthrough behavior. If `$attrs` are not bound explicitly, a runtime warning will be issued.
117+
ルート要素が一つでなく、複数のルート要素からなるコンポーネントには、自動的に属性の継承が行われることはありません。`$attrs` を用いた明示的なアサインを行わない場合、ランタイム上で warning が発行されます。
115118

116119
```html
117120
<custom-layout id="custom-layout" @click="changeValue"></custom-layout>
118121
```
119122

120123
```js
121-
// This will raise a warning
124+
// これは warning を発行します
122125
app.component('custom-layout', {
123126
template: `
124127
<header>...</header>
@@ -127,7 +130,7 @@ app.component('custom-layout', {
127130
`
128131
})
129132

130-
// No warnings, $attrs are passed to <main> element
133+
// <main> 要素に $attrs で属性を渡しているため、 warnings は発行されません
131134
app.component('custom-layout', {
132135
template: `
133136
<header>...</header>

0 commit comments

Comments
 (0)