You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/forms.md
+47-47Lines changed: 47 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,25 @@
1
-
# Form Input Bindings
1
+
# フォーム入力バインディング
2
2
3
-
## Basic Usage
3
+
## 基本的な使い方
4
4
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)です。
6
6
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.
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.
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.
<!-- `selected` is a string "abc" when the first option is selected-->
243
+
<!--最初のオプションが選択されているとき`selected` は文字列"abc"です-->
244
244
<selectv-model="selected">
245
245
<optionvalue="abc">ABC</option>
246
246
</select>
247
247
```
248
248
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.
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.
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:
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`修飾子を加えることができます。
308
307
309
308
```html
310
309
<inputv-model.number="age"type="number" />
311
310
```
312
311
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()` でパースできない場合は、元々の値が返却されます。
314
313
315
314
### `.trim`
316
315
317
-
If you want whitespace from user input to be trimmed automatically, you can add the `trim`modifier to your `v-model`-managed inputs:
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