Skip to content

Commit 9e3a947

Browse files
committed
Essentials > Form Input Bindings の翻訳
1 parent 032c9d5 commit 9e3a947

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/guide/forms.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Form Input Bindings
1+
# フォーム入力バインディング
22

3-
## Basic Usage
3+
## 基本的な使い方
44

5-
You can use the `v-model` directive to create two-way data bindings on form input, textarea, and select elements. It automatically picks the correct way to update the element based on the input type. Although a bit magical, `v-model` is essentially syntax sugar for updating data on user input events, plus special care for some edge cases.
5+
form の input 要素 や textarea 要素、 select 要素に双方向データバインディングを付与するためには、`v-model`を使用することができます。`v-model`は、要素の適切な更新方法を入力の種類に基づいて自動で選択します。ちょっと魔法のようですが、`v-model`は本来、ユーザの入力イベントに応じてデータを更新し、加えていくつかのエッジケースに対して特別な配慮をしてくれる糖衣構文(syntax sugar)です。
66

7-
::: tip Note
8-
`v-model` will ignore the initial `value`, `checked` or `selected` attributes found on any form elements. It will always treat the current active instance data as the source of truth. You should declare the initial value on the JavaScript side, inside the `data` option of your component.
7+
::: tip
8+
`v-model` はフォーム要素の`value`属性や`checked`属性、`selected`属性の初期値を無視します。`v-model`は常に、現在アクティブなインスタンスの`data`を信頼できる情報源として扱います。初期値の宣言はJavaScript側、コンポーネントの`data`オプション内で宣言すべきです。
99
:::
1010

11-
`v-model` internally uses different properties and emits different events for different input elements:
11+
内部的には、`v-model`は異なる input 要素に対し異なるプロパティを使用し、異なるイベントを送出します。
1212

13-
- text and textarea elements use `value` property and `input` event;
14-
- checkboxes and radiobuttons use `checked` property and `change` event;
15-
- select fields use `value` as a prop and `change` as an event.
13+
- text および textarea 要素には、`value`プロパティと`input`イベントを用います
14+
- チェックボックスおよびラジオボタンには、`checked`プロパティと`change`イベントを用います
15+
- select フィールドには、`value`プロパティと`change`イベントを用います
1616

1717
<span id="vmodel-ime-tip"></span>
1818
::: tip Note
19-
For languages that require an [IME](https://en.wikipedia.org/wiki/Input_method) (Chinese, Japanese, Korean etc.), you'll notice that `v-model` doesn't get updated during IME composition. If you want to cater for these updates as well, use `input` event instead.
19+
[IME](https://ja.wikipedia.org/wiki/%E3%82%A4%E3%83%B3%E3%83%97%E3%83%83%E3%83%88%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89) を必要とする言語 (中国語、日本語、韓国語など) において、IME で入力している間は`v-model`が更新を行わないことに気づくでしょう。このような入力に対しても同様に対応したい場合は、代わりに`input` イベントを使用してください。
2020
:::
2121

22-
### Text
22+
### テキスト
2323

2424
```html
2525
<input v-model="message" placeholder="edit me" />
@@ -33,7 +33,7 @@ For languages that require an [IME](https://en.wikipedia.org/wiki/Input_method)
3333
</p>
3434
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
3535

36-
### Multiline text
36+
### 複数行テキスト
3737

3838
```html
3939
<span>Multiline message is:</span>
@@ -49,7 +49,7 @@ For languages that require an [IME](https://en.wikipedia.org/wiki/Input_method)
4949
</p>
5050
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
5151

52-
Interpolation on textareas won't work. Use `v-model` instead.
52+
textarea への挿入は機能しません。代わりに`v-model`を用いてください。
5353

5454
```html
5555
<!-- bad -->
@@ -59,9 +59,9 @@ Interpolation on textareas won't work. Use `v-model` instead.
5959
<textarea v-model="text"></textarea>
6060
```
6161

62-
### Checkbox
62+
### チェックボックス
6363

64-
Single checkbox, boolean value:
64+
単一のチェックボックスと boolean 値:
6565

6666
```html
6767
<input type="checkbox" id="checkbox" v-model="checked" />
@@ -75,7 +75,7 @@ Single checkbox, boolean value:
7575
</p>
7676
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
7777

78-
Multiple checkboxes, bound to the same Array:
78+
同じ配列にバインドされた複数のチェックボックス:
7979

8080
```html
8181
<div id="v-model-multiple-checkboxes">
@@ -107,7 +107,7 @@ Vue.createApp({
107107
</p>
108108
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
109109

110-
### Radio
110+
### ラジオ
111111

112112
```html
113113
<div id="v-model-radiobutton">
@@ -138,9 +138,9 @@ Vue.createApp({
138138
</p>
139139
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
140140

141-
### Select
141+
### セレクト
142142

143-
Single select:
143+
単一のセレクト:
144144

145145
```html
146146
<div id="v-model-select" class="demo">
@@ -172,10 +172,10 @@ Vue.createApp({
172172
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
173173

174174
:::tip Note
175-
If the initial value of your `v-model` expression does not match any of the options, the `<select>` element will render in an "unselected" state. On iOS this will cause the user not being able to select the first item because iOS does not fire a change event in this case. It is therefore recommended to provide a disabled option with an empty value, as demonstrated in the example above.
175+
`v-model`の式の初期値がいずれのオプションとも一致しない場合、`<select>`要素は *未選択* の状態で描画されます。これにより iOS では最初のアイテムが選択できなくなります。なぜなら iOS はこのような場合に `change` イベントを発火させないためです。したがって、上記の例で示したように`value`を持たない`disabled` なオプションを追加しておくことをおすすめします。
176176
:::
177177

178-
Multiple select (bound to Array):
178+
複数個のセレクト(配列にバインド):
179179

180180
```html
181181
<select v-model="selected" multiple>
@@ -194,7 +194,7 @@ Multiple select (bound to Array):
194194
</p>
195195
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
196196

197-
Dynamic options rendered with `v-for`:
197+
動的なオプションを`v-for`により描画:
198198

199199
```html
200200
<div id="v-model-select-dynamic" class="demo">
@@ -229,99 +229,99 @@ Vue.createApp({
229229
</p>
230230
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
231231

232-
## Value Bindings
232+
## 値のバインディング
233233

234-
For radio, checkbox and select options, the `v-model` binding values are usually static strings (or booleans for checkbox):
234+
ラジオやチェックボックス、セレクトの option において、`v-model`でバインディングされる値は通常は静的な文字列(チェックボックスの場合はbooleanも)です:
235235

236236
```html
237-
<!-- `picked` is a string "a" when checked -->
237+
<!-- チェックされているとき`picked` は文字列"a"になります -->
238238
<input type="radio" v-model="picked" value="a" />
239239

240-
<!-- `toggle` is either true or false -->
240+
<!-- toggle` true または false のどちらかです -->
241241
<input type="checkbox" v-model="toggle" />
242242

243-
<!-- `selected` is a string "abc" when the first option is selected -->
243+
<!-- 最初のオプションが選択されているとき`selected` は文字列"abc"です -->
244244
<select v-model="selected">
245245
<option value="abc">ABC</option>
246246
</select>
247247
```
248248

249-
But sometimes we may want to bind the value to a dynamic property on the current active instance. We can use `v-bind` to achieve that. In addition, using `v-bind` allows us to bind the input value to non-string values.
249+
しかし時には、現在アクティブなインスタンスの動的なプロパティに値をバインドしたくなるかもしれません。それを実現するためには`v-bind`が使用できます。さらに`v-bind`を使用することで入力値に文字列以外の値もバインドできるようになります。
250250

251-
### Checkbox
251+
### チェックボックス
252252

253253
```html
254254
<input type="checkbox" v-model="toggle" true-value="yes" false-value="no" />
255255
```
256256

257257
```js
258-
// when checked:
258+
// チェックされているとき:
259259
vm.toggle === 'yes'
260-
// when unchecked:
260+
// チェックされていないとき:
261261
vm.toggle === 'no'
262262
```
263263

264264
:::tip Tip
265-
The `true-value` and `false-value` attributes don't affect the input's `value` attribute, because browsers don't include unchecked boxes in form submissions. To guarantee that one of two values is submitted in a form (e.g. "yes" or "no"), use radio inputs instead.
265+
`true-value` `false-value` 属性は input`value` 属性には影響を及ぼしません。なぜならブラウザはチェックされていないチェックボックスをフォーム送信内容には含めないためです。二つの値(例:"yes" または "no")のうち一つが必ず送信されることを保証するには、代わりにラジオを使用してください。
266266
:::
267267

268-
### Radio
268+
### ラジオ
269269

270270
```html
271271
<input type="radio" v-model="pick" v-bind:value="a" />
272272
```
273273

274274
```js
275-
// when checked:
275+
// チェックされているとき:
276276
vm.pick === vm.a
277277
```
278278

279-
### Select Options
279+
### セレクトオプション
280280

281281
```html
282282
<select v-model="selected">
283-
<!-- inline object literal -->
283+
<!-- インラインオブジェクトリテラル -->
284284
<option :value="{ number: 123 }">123</option>
285285
</select>
286286
```
287287

288288
```js
289-
// when selected:
289+
// 選択されているとき:
290290
typeof vm.selected // => 'object'
291291
vm.selected.number // => 123
292292
```
293293

294-
## Modifiers
294+
## 修飾子
295295

296296
### `.lazy`
297-
298-
By default, `v-model` syncs the input with the data after each `input` event (with the exception of IME composition as [stated above](#vmodel-ime-tip)). You can add the `lazy` modifier to instead sync after `change` events:
297+
デフォルトでは`v-model`は各`input`イベント後に入力値とデータを同期します([上述](#vmodel-ime-tip)のIME入力の例外はあります)。`lazy` 修飾子を加えることで、`change`イベント後に同期するよう変更できます。
299298

300299
```html
301-
<!-- synced after "change" instead of "input" -->
300+
<!-- "input" ではなく "change" イベントの後に同期されます -->
302301
<input v-model.lazy="msg" />
303302
```
304303

305304
### `.number`
306305

307-
If you want user input to be automatically typecast as a number, you can add the `number` modifier to your `v-model` managed inputs:
306+
ユーザ入力を自動的に number へ型キャストさせたい場合は、`v-model`で管理している input に`number`修飾子を加えることができます。
308307

309308
```html
310309
<input v-model.number="age" type="number" />
311310
```
312311

313-
This is often useful, because even with `type="number"`, the value of HTML input elements always returns a string. If the value cannot be parsed with `parseFloat()`, then the original value is returned.
312+
これはしばしば有用です。なぜなら`type="number"`が書いてあったとしても HTML input 要素は常に文字列を返すためです。値が`parseFloat()` でパースできない場合は、元々の値が返却されます。
314313

315314
### `.trim`
316315

317-
If you want whitespace from user input to be trimmed automatically, you can add the `trim` modifier to your `v-model`-managed inputs:
316+
ユーザ入力から空白を自動で取り除きたい場合は、`v-model`で管理している input `trim` 修飾子を加えることができます。
318317

319318
```html
320319
<input v-model.trim="msg" />
321320
```
322321

323-
## `v-model` with Components
322+
## コンポーネントの`v-model`
323+
324+
> まだ Vue コンポーネントに慣れていない場合、この節は一旦スキップすることができます。
324325
325-
> If you're not yet familiar with Vue's components, you can skip this for now.
326+
HTML組み込みの input タイプが、常にあなたのニーズに沿っているとは限りません。幸いにも、Vue コンポーネントによって動作を隅々までカスタマイズ可能な再利用性のある入力フォームを自作することができます。それらのフォームに`v-model`を使うことも可能です!詳しくは、コンポーネントガイドの [カスタム input](./component-basics.html#using-v-model-on-components) を参照してください。
326327

327-
HTML's built-in input types won't always meet your needs. Fortunately, Vue components allow you to build reusable inputs with completely customized behavior. These inputs even work with `v-model`! To learn more, read about [custom inputs](./component-basics.html#using-v-model-on-components) in the Components guide.

0 commit comments

Comments
 (0)