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
Unlike components and props, event names don't provide any automatic case transformation. Instead, the name of an emitted event must exactly match the name used to listen to that event. For example, if emitting a camelCased event name:
Since event names will never be used as variable or property names in JavaScript, there is no reason to use camelCase or PascalCase. Additionally,`v-on`event listeners inside DOM templates will be automatically transformed to lowercase (due to HTML's case-insensitivity), so `@myEvent`would become `@myevent`-- making `myEvent`impossible to listen to.
20
+
イベント名は JavaScript 内で変数やプロパティ名として扱われることはないので、キャメルケース(camelCase)またはパスカルケース(PascalCase)を使用する理由はありません。 さらに DOM テンプレート内の`v-on`イベントリスナは自動的に小文字に変換されます ( HTML が大文字と小文字を判別しないため)。このため `@myEvent`は `@myevent`になり `myEvent`にリスナが反応することができなくなります。
21
21
22
-
For these reasons, we recommend you **always use kebab-case for event names**.
22
+
こういった理由から **いつもケバブケース(kebab-case)を使うこと** をお薦めします。
23
23
24
-
## Defining Custom Events
24
+
## カスタムイベントの定義
25
25
26
-
Emitted events can be defined on the component via the `emits`option.
26
+
発行されたイベントは、 `emits`オプションを介して、コンポーネントで定義することが出来ます。
27
27
28
28
```js
29
29
app.component('custom-form', {
30
30
emits: ['in-focus', 'submit']
31
31
})
32
32
```
33
33
34
-
In the event a native event (e.g., `click`) is defined in the `emits` option, it will be overwritten by the event in the component instead of being treated as a native listener.
To add validation, the event is assigned a function that receives the arguments passed to the `$emit`call and returns a boolean to indicate whether the event is valid or not.
By default, `v-model`on a component uses `modelValue`as the prop and `update:modelValue`as the event. We can modify these names passing an argument to `v-model`:
By leveraging the ability to target a particular prop and event as we learned before with [`v-model`arguments](#v-model-arguments), we can now create multiple v-model bindings on a single component instance.
When we were learning about form input bindings, we saw that `v-model` has [built-in modifiers](/guide/forms.html#modifiers) - `.trim`, `.number` and `.lazy`. In some cases, however, you might also want to add your own custom modifiers.
145
145
146
-
Let's create an example custom modifier, `capitalize`, that capitalizes the first letter of the string provided by the `v-model` binding.
Modifiers added to a component `v-model`will be provided to the component via the `modelModifiers`prop. In the below example, we have created a component that contains a `modelModifiers`prop that defaults to an empty object.
Notice that when the component's `created`lifecycle hook triggers, the `modelModifiers`prop contains `capitalize`and its value is `true`- due to it being set on the `v-model`binding`v-model.capitalize="bar"`.
Now that we have our prop set up, we can check the `modelModifiers`object keys and write a handler to change the emitted value. In the code below we will capitalize the string whenever the `<input />`element fires an `input`event.
0 commit comments