Skip to content

Commit 391a4bb

Browse files
committed
add docs
1 parent 892f277 commit 391a4bb

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/rules/no-shadow-native-events.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-shadow-native-events
5+
description: disallow `emits` which would shadow native html events
6+
---
7+
# vue/no-shadow-native-events
8+
9+
> disallow `emits` which would shadow native HTML events
10+
11+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> _**This rule has not been released yet.**_ </badge>
12+
13+
## :book: Rule Details
14+
15+
This rule reports emits that shadow native HTML events. (The `emits` option is a new in Vue.js 3.0.0+)
16+
17+
Using native event names for emits can lead to incorrect assumptions about an emit and cause confusion. This is caused by Vue emits behaving differently from native events. E.g. :
18+
- The payload of an emit can be chosen arbitrarily
19+
- Vue emits do not bubble, while most native events do
20+
- [Event modifiers](https://vuejs.org/guide/essentials/event-handling.html#event-modifiers) only work on HTML events or when the original event is re-emitted as emit payload.
21+
- When the native event is remitted the `event.target` might not match the actual event-listeners location.
22+
23+
The rule is mostly aimed at developers of component libraries.
24+
25+
<eslint-code-block :rules="{'vue/no-shadow-native-events': ['error']}">
26+
27+
```vue
28+
<template>
29+
<!-- ✓ GOOD -->
30+
<button @click="$emit('close')">Close</button>
31+
<!-- ✗ BAD -->
32+
<button @click="$emit('click')">Close</button>
33+
</template>
34+
```
35+
36+
</eslint-code-block>
37+
38+
## :wrench: Options
39+
40+
Nothing.
41+
42+
## :couple: Related Rules
43+
44+
- [vue/no-unused-emit-declarations](./no-unused-emit-declarations.md)
45+
- [vue/require-explicit-emits](./require-explicit-emits.md)
46+
47+
## :books: Further Reading
48+
49+
- [Components In-Depth - Events / Component Events ](https://vuejs.org/guide/components/events.html#event-arguments)
50+
- [Vue RFCs - 0030-emits-option](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0030-emits-option.md)

0 commit comments

Comments
 (0)