Skip to content

Commit 3915a1f

Browse files
committed
docs: translate guide > data properties and methods
1 parent 8f780b6 commit 3915a1f

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/guide/data-methods.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Data Properties and Methods
1+
# データプロパティとメソッド
22

3-
## Data Properties
3+
## データプロパティ
44

5-
The `data` option for a component is a function. Vue calls this function as part of creating a new component instance. It should return an object, which Vue will then wrap in its reactivity system and store on the component instance as `$data`. For convenience, any top-level properties of that object are also exposed directly via the component instance:
5+
コンポーネントの `data` オプションは関数です。Vue は新しいコンポーネントのインスタンスを作成する際に、この関数を呼び出します。これはオブジェクトを返すもので、 Vue はオブジェクトをそのリアクティブシステムでラップして、コンポーネントのインスタンスに `$data` として格納します。便宜上、そのオブジェクトのトップレベルのプロパティは、コンポーネントのインスタンスを介して直接公開されます:
66

77
```js
88
const app = Vue.createApp({
@@ -16,24 +16,24 @@ const vm = app.mount('#app')
1616
console.log(vm.$data.count) // => 4
1717
console.log(vm.count) // => 4
1818

19-
// Assigning a value to vm.count will also update $data.count
19+
// vm.count に値を代入すると、 $data.count も更新
2020
vm.count = 5
2121
console.log(vm.$data.count) // => 5
2222

23-
// ... and vice-versa
23+
// ... 逆もまた同様
2424
vm.$data.count = 6
2525
console.log(vm.count) // => 6
2626
```
2727

28-
These instance properties are only added when the instance is first created, so you need to ensure they are all present in the object returned by the `data` function. Where necessary, use `null`, `undefined` or some other placeholder value for properties where the desired value isn't yet available.
28+
これらのインスタンスプロパティは、インスタンスの初回作成時にのみ追加されます。そのため、 `data` 関数から返されたオブジェクトに、それらがすべて含まれていることを確認する必要があります。必要に応じて、必要な値がまだ利用できないプロパティには、 `null``undefined` 、またはその他のプレースホルダーの値を使ってください。
2929

30-
It is possible to add a new property directly to the component instance without including it in `data`. However, because this property isn't backed by the reactive `$data` object, it won't automatically be tracked by [Vue's reactivity system](reactivity.html).
30+
新しいプロパティを `data` に含めずに、コンポーネントのインスタンスに直接追加することはできます。しかし、このプロパティはリアクティブな `$data` オブジェクトによって裏付けされていないので、 [Vue のリアクティブシステム](reactivity.html) によって、自動的に追跡されることはありません。
3131

32-
Vue uses a `$` prefix when exposing its own built-in APIs via the component instance. It also reserves the prefix `_` for internal properties. You should avoid using names for top-level `data` properties that start with either of these characters.
32+
Vue は、コンポーネントのインスタンスを介して自身のビルトイン API を公開する際に、 `$` をプレフィックスに使います。 また、内部プロパティのために `_` を予約しています。トップレベルの `data` プロパティの名前に、これらの文字からはじまる名前を使うことは避けるべきです。
3333

34-
## Methods
34+
## メソッド
3535

36-
To add methods to a component instance we use the `methods` option. This should be an object containing the desired methods:
36+
コンポーネントのインスタンスにメソッドを追加するには、 `methods` オプションを使います。これは必要なメソッドを含むオブジェクトでなければなりません:
3737

3838
```js
3939
const app = Vue.createApp({
@@ -42,7 +42,7 @@ const app = Vue.createApp({
4242
},
4343
methods: {
4444
increment() {
45-
// `this` will refer to the component instance
45+
// `this` はコンポーネントインスタンスを参照
4646
this.count++
4747
}
4848
}
@@ -57,63 +57,63 @@ vm.increment()
5757
console.log(vm.count) // => 5
5858
```
5959

60-
Vue automatically binds the `this` value for `methods` so that it always refers to the component instance. This ensures that a method retains the correct `this` value if it's used as an event listener or callback. You should avoid using arrow functions when defining `methods`, as that prevents Vue from binding the appropriate `this` value.
60+
Vue は、 `methods` `this` を自動的に束縛して、常にコンポーネントのインスタンスを参照します。これにより、メソッドがイベントリスナやコールバックとして使われる際に、正しい `this` の値を保持することができます。Vue が適切な `this` の値を束縛するのを防ぐため、 `methods` を定義する際にはアロー関数を使うのは避けるべきです。
6161

62-
Just like all other properties of the component instance, the `methods` are accessible from within the component's template. Inside a template they are most commonly used as event listeners:
62+
コンポーネントのインスタンスの他のすべてのプロパティと同様に、 `methods` はコンポーネントのテンプレート内からアクセスできます。テンプレート内からはよくイベントリスナとして使われます:
6363

6464
```html
6565
<button @click="increment">Up vote</button>
6666
```
6767

68-
In the example above, the method `increment` will be called when the `<button>` is clicked.
68+
上の例では、 `<button>` がクリックされると、 `increment` メソッドが呼ばれます。
6969

70-
It is also possible to call a method directly from a template. As we'll see shortly, it's usually better to use a [computed property](computed.html) instead. However, using a method can be useful in scenarios where computed properties aren't a viable option. You can call a method anywhere that a template supports JavaScript expressions:
70+
また、テンプレートから直接メソッドを呼び出すこともできます。後で説明しますが、通常は変わりに [算出プロパティ](computed.html) を使うのがよいです。しかし、メソッドを使うことは算出プロパティが実行可能なオプションではない場合に役に立ちます。テンプレートが JavaScript の式をサポートしていれば、どこでもメソッドを呼び出すことができます:
7171

7272
```html
7373
<span :title="toTitleDate(date)">
7474
{{ formatDate(date) }}
7575
</span>
7676
```
7777

78-
If the methods `toTitleDate` or `formatDate` access any reactive data then it will be tracked as a rendering dependency, just as if it had been used in the template directly.
78+
`toTitleDate` `formatDate` メソッドがどれかリアクティブなデータにアクセスすると、あたかもテンプレートで直接使われていたかのように、それはレンダリングの依存関係として追跡されます。
7979

80-
Methods called from a template should not have any side effects, such as changing data or triggering asynchronous processes. If you find yourself tempted to do that you should probably use a [lifecycle hook](instance.html#lifecycle-hooks) instead.
80+
テンプレートから呼び出されたメソッドは、データの変更や非同期処理の発火などの副作用があってはなりません。もしそのようなことをしたくなったら、代わりに [ライフサイクルフック](instance.html#lifecycle-hooks) を使うべきです。
8181

82-
### Debouncing and Throttling
82+
### Debounce (デバウンス) と Throttle (スロットル)
8383

84-
Vue doesn't include built-in support for debouncing or throttling but it can be implemented using libraries such as [Lodash](https://lodash.com/).
84+
Vue は、 デバウンスやスロットルのサポートが組み込まれていませんが、 [Lodash](https://lodash.com/) などのライブラリを使って実装することができます。
8585

86-
In cases where a component is only used once, the debouncing can be applied directly within `methods`:
86+
コンポーネントが一度しか使われない場合には、 `methods` の中で直接デバウンスを適用することができます:
8787

8888
```html
8989
<script src="https://unpkg.com/lodash@4.17.20/lodash.min.js"></script>
9090
<script>
9191
Vue.createApp({
9292
methods: {
93-
// Debouncing with Lodash
93+
// Lodash によるデバウンス
9494
click: _.debounce(function() {
95-
// ... respond to click ...
95+
// ... クリックに反応 ...
9696
}, 500)
9797
}
9898
}).mount('#app')
9999
</script>
100100
```
101101

102-
However, this approach is potentially problematic for components that are reused because they'll all share the same debounced function. To keep the component instances independent from each other, we can add the debounced function in the `created` lifecycle hook:
102+
しかし、この方法ではコンポーネントが再利用される場合に、すべてのコンポーネントが同じデバウンス関数を共有するため、問題が起きる可能性があります。コンポーネントのインスタンスをお互いに独立させるために、 `created` ライフサイクルフックにデバウンス関数を追加することができます:
103103

104104
```js
105105
app.component('save-button', {
106106
created() {
107-
// Debouncing with Lodash
107+
// Lodash によるデバウンス
108108
this.debouncedClick = _.debounce(this.click, 500)
109109
},
110110
unmounted() {
111-
// Cancel the timer when the component is removed
111+
// コンポーネントが削除されたらタイマーをキャンセル
112112
this.debouncedClick.cancel()
113113
},
114114
methods: {
115115
click() {
116-
// ... respond to click ...
116+
// ... クリックに反応 ...
117117
}
118118
},
119119
template: `

0 commit comments

Comments
 (0)