diff --git a/_config.yml b/_config.yml index 9dc360366..9d2207cf1 100644 --- a/_config.yml +++ b/_config.yml @@ -187,4 +187,3 @@ alias: examples/svg.html: v2/examples/svg.html examples/todomvc.html: v2/examples/todomvc.html examples/tree-view.html: v2/examples/tree-view.html - diff --git a/package.json b/package.json index f01a31d00..a61914260 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jp.vuejs.org", "private": true, "hexo": { - "version": "3.4.4" + "version": "3.6.0" }, "dependencies": { "hexo": "^3.4.2", diff --git a/src/v2/api/index.md b/src/v2/api/index.md index c119f7c58..53e72e732 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -1434,7 +1434,7 @@ updated: 2018-03-21 - **詳細:** - 親スコープの (`.native` 修飾子なしの) `v-on` イベントリスナーを含みます。これは、`v-on="$listeners"` を介して内部コンポーネントに渡すことができます。高次コンポーネントを作成するときに便利です。 + 親スコープの (`.native` 修飾子なしの) `v-on` イベントリスナーを含みます。これは、`v-on="$listeners"` を介して内部コンポーネントに渡すことができます。透過的なラッパーコンポーネントを作成するときに便利です。 ## インスタンスメソッド / データ diff --git a/src/v2/guide/components-custom-events.md b/src/v2/guide/components-custom-events.md new file mode 100644 index 000000000..b6bbc7327 --- /dev/null +++ b/src/v2/guide/components-custom-events.md @@ -0,0 +1,170 @@ +--- +title: Custom Events +type: guide +order: 103 +--- + +> ⚠️注意: この内容は原文のままです。現在翻訳中ですのでお待ち下さい。🙏 + +> This page assumes you've already read the [Components Basics](components.html). Read that first if you are new to components. + +## Event Names + +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: + +```js +this.$emit('myEvent') +``` + +Listening to the kebab-cased version will have no effect: + +```html + +``` + +Unlike components and props, event names will never be used as variable or property names in JavaScript, so there's 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 `v-on:myEvent` would become `v-on:myevent` -- making `myEvent` impossible to listen to. + +For these reasons, we recommend you **always use kebab-case for event names**. + +## Customizing Component `v-model` + +> New in 2.2.0+ + +By default, `v-model` on a component uses `value` as the prop and `input` as the event, but some input types such as checkboxes and radio buttons may want to use the `value` attribute for a [different purpose](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#Value). Using the `model` option can avoid a conflict in such cases: + +```js +Vue.component('base-checkbox', { + model: { + prop: 'checked', + event: 'change' + }, + props: { + checked: Boolean + }, + template: ` + + ` +}) +``` + +Now when using `v-model` on this component: + +```js + +``` + +the value of `lovingVue` will be passed to the `checked` prop. The `lovingVue` property will then be updated when `` emits a `change` event with a new value. + +

Note that you still have to declare the checked prop in component's props option.

+ +## Binding Native Events to Components + +There may be times when you want to listen directly to a native event on the root element of a component. In these cases, you can use the `.native` modifier for `v-on`: + +```html + +``` + +This can be useful sometimes, but it's not a good idea when you're trying to listen on a very specific element, like an ``. For example, the `` component above might refactor so that the root element is actually a `