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
Copy file name to clipboardExpand all lines: source/guide/events.md
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,8 +27,6 @@ new Vue({
27
27
})
28
28
```
29
29
30
-
One thing to note is that internally, Vue.js uses event delegation for all `v-on` handlers. Vue.js ensures that `event.stopPropagation()` and `event.preventDefault()` will work like normal listeners, but `event.currentTarget` will always point to the ViewModel's root element. In cases where `event.target` is a childNode of the actual element that the `v-on` directive is bound to, the element with `v-on` will be available as `event.delegationTarget`.
31
-
32
30
## Invoke Handler with Expression
33
31
34
32
`targetVM` could be useful when `v-on` is used with `v-repeat`, since the latter creates a lot of child ViewModels. However, it is often more convenient to use an invocation expression passing in `this`, which equals the current context ViewModel:
@@ -98,7 +96,6 @@ You might be concerned about this whole event listening approach violates the go
98
96
99
97
1. It makes it easier to locate the handler function implementations within your JS code by simply skimming the HTML template.
100
98
2. Since you don't have to manually attach event listeners in JS, your ViewModel code can be pure logic and DOM-free. This makes it easier to test.
101
-
3. When a ViewModel is destroyed, all event listeners are automatically removed.
102
-
4. Vue.js automatically uses event delegation on each VM's root element instead of attaching a listner on every Node. Listeners on `v-repeat` instances are delegated together on their parent ViewModel.
99
+
3. When a ViewModel is destroyed, all event listeners are automatically removed. You don't need to worry about cleaning it up yourself.
0 commit comments