Skip to content

Commit 2ccbaef

Browse files
Merge branch 'master' of github.com:vuejs/docs-next
2 parents 363641a + 2706494 commit 2ccbaef

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

src/guide/component-basics.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ Which can be used in the template to control the font size of all blog posts:
178178
```html
179179
<div id="blog-posts-events-demo">
180180
<div :style="{ fontSize: postFontSize + 'em' }">
181-
<blog-post v-for="post in posts" :key="post.id" :title="post.title"></blog-post>
181+
<blog-post
182+
v-for="post in posts"
183+
:key="post.id"
184+
:title="post.title"
185+
></blog-post>
182186
</div>
183187
</div>
184188
```
@@ -216,7 +220,7 @@ When we click on the button, we need to communicate to the parent that it should
216220
Then the child component can emit an event on itself by calling the built-in [**`$emit`** method](../api/instance-methods.html#emit), passing the name of the event:
217221

218222
```html
219-
<button @click="$emit('enlarge-text')">
223+
<button @click="$emit('enlargeText')">
220224
Enlarge text
221225
</button>
222226
```
@@ -230,7 +234,7 @@ We can list emitted events in the component's `emits` option:
230234
```js
231235
app.component('blog-post', {
232236
props: ['title'],
233-
emits: ['enlarge-text']
237+
emits: ['enlargeText']
234238
})
235239
```
236240

@@ -241,7 +245,7 @@ This will allow you to check all the events that a component emits and optionall
241245
It's sometimes useful to emit a specific value with an event. For example, we may want the `<blog-post>` component to be in charge of how much to enlarge the text by. In those cases, we can pass a second parameter to `$emit` to provide this value:
242246

243247
```html
244-
<button @click="$emit('enlarge-text', 0.1)">
248+
<button @click="$emit('enlargeText', 0.1)">
245249
Enlarge text
246250
</button>
247251
```

src/guide/component-custom-events.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,17 @@
44
55
## Event Names
66

7-
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.
8-
9-
```js
10-
this.$emit('my-event')
11-
```
12-
13-
```html
14-
<my-component @my-event="doSomething"></my-component>
15-
```
16-
17-
If we're emitting a camelCased event name:
7+
Like components and props, event names provide an automatic case transformation. If you emit an event from the child component in camel case, you will be able to add a kebab-cased listener in the parent:
188

199
```js
2010
this.$emit('myEvent')
2111
```
2212

23-
Listening to the kebab-cased version will have no effect:
24-
2513
```html
26-
<!-- Won't work -->
2714
<my-component @my-event="doSomething"></my-component>
2815
```
2916

30-
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.
31-
32-
For these reasons, we recommend you **always use kebab-case for event names**.
17+
As with [props casing](/guide/component-props.html#prop-casing-camelcase-vs-kebab-case), we recommend using kebab-cased event listeners when you are using in-DOM templates. If you're using string templates, this limitation does not apply.
3318

3419
## Defining Custom Events
3520

@@ -39,7 +24,7 @@ Emitted events can be defined on the component via the `emits` option.
3924

4025
```js
4126
app.component('custom-form', {
42-
emits: ['in-focus', 'submit']
27+
emits: ['inFocus', 'submit']
4328
})
4429
```
4530

src/guide/migration/async-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const asyncPageWithOptions = defineAsyncComponent({
6666
loader: () => import('./NextPage.vue'),
6767
delay: 200,
6868
timeout: 3000,
69-
error: ErrorComponent,
70-
loading: LoadingComponent
69+
errorComponent: ErrorComponent,
70+
loadingComponent: LoadingComponent
7171
})
7272
```
7373

src/guide/single-file-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default {
102102
// this is an array of outputed formats
103103
output: [
104104
{
105-
file: pkg.module, // the name of our esm librry
105+
file: pkg.module, // the name of our esm library
106106
format: 'esm', // the format of choice
107107
sourcemap: true, // ask rollup to include sourcemaps
108108
}

0 commit comments

Comments
 (0)