From e554cd6f15fb201d8dc9e03e0f07e4a80e776f19 Mon Sep 17 00:00:00 2001 From: skirtle <65301168+skirtles-code@users.noreply.github.com> Date: Sat, 21 Nov 2020 08:50:07 +0000 Subject: [PATCH] fix: add an emits option to examples that emit events (#705) --- src/api/instance-methods.md | 8 ++++++-- src/guide/component-basics.md | 2 ++ src/guide/component-custom-events.md | 21 +++++++++++---------- src/guide/list.md | 3 ++- src/guide/migration/v-model.md | 1 + src/guide/render-function.md | 1 + 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/api/instance-methods.md b/src/api/instance-methods.md index fb9bc0f04d..2698fab663 100644 --- a/src/api/instance-methods.md +++ b/src/api/instance-methods.md @@ -222,6 +222,7 @@ }) app.component('welcome-button', { + emits: ['welcome'], template: ` ` }) + + app.mount('#emit-example-argument') ``` - **See also:** diff --git a/src/guide/component-basics.md b/src/guide/component-basics.md index 9bc6c52198..366d939b12 100644 --- a/src/guide/component-basics.md +++ b/src/guide/component-basics.md @@ -303,6 +303,7 @@ Here's that in action: ```js app.component('custom-input', { props: ['modelValue'], + emits: ['update:modelValue'], template: ` `, diff --git a/src/guide/component-custom-events.md b/src/guide/component-custom-events.md index 9ed4315fce..84d2943cc3 100644 --- a/src/guide/component-custom-events.md +++ b/src/guide/component-custom-events.md @@ -90,12 +90,11 @@ By default, `v-model` on a component uses `modelValue` as the prop and `update:m In this case, child component will expect a `title` prop and emits `update:title` event to sync: ```js -const app = Vue.createApp({}) - app.component('my-component', { props: { title: String }, + emits: ['update:title'], template: ` + ``` ```js @@ -168,6 +166,7 @@ app.component('my-component', { default: () => ({}) } }, + emits: ['update:modelValue'], template: ` ({}) } }, + emits: ['update:modelValue'], methods: { emitValue(e) { let value = e.target.value @@ -225,19 +225,20 @@ app.mount('#app') For `v-model` bindings with arguments, the generated prop name will be `arg + "Modifiers"`: ```html - + ``` ```js app.component('my-component', { - props: ['foo', 'fooModifiers'], + props: ['description', 'descriptionModifiers'], + emits: ['update:description'], template: ` + :value="description" + @input="$emit('update:description', $event.target.value)"> `, created() { - console.log(this.fooModifiers) // { capitalize: true } + console.log(this.descriptionModifiers) // { capitalize: true } } }) ``` diff --git a/src/guide/list.md b/src/guide/list.md index 5802864bbb..ec4be39071 100644 --- a/src/guide/list.md +++ b/src/guide/list.md @@ -345,7 +345,8 @@ app.component('todo-item', { `, - props: ['title'] + props: ['title'], + emits: ['remove'] }) app.mount('#todo-list-example') diff --git a/src/guide/migration/v-model.md b/src/guide/migration/v-model.md index c035f04c6f..22b5a96a26 100644 --- a/src/guide/migration/v-model.md +++ b/src/guide/migration/v-model.md @@ -173,6 +173,7 @@ We recommend: props: { modelValue: String // previously was `value: String` }, + emits: ['update:modelValue'], methods: { changePageTitle(title) { this.$emit('update:modelValue', title) // previously was `this.$emit('input', title)` diff --git a/src/guide/render-function.md b/src/guide/render-function.md index 72223123ea..24bee155dd 100644 --- a/src/guide/render-function.md +++ b/src/guide/render-function.md @@ -274,6 +274,7 @@ The `v-model` directive is expanded to `modelValue` and `onUpdate:modelValue` pr ```js props: ['modelValue'], +emits: ['update:modelValue'], render() { return Vue.h(SomeComponent, { modelValue: this.modelValue,