-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
68 lines (61 loc) · 1.94 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<main>
<div
v-if="show"
class="main__warp"
v-delegate:click-a.left="['.event-block__warp', clickTexts1]"
v-delegate:click-b.left.capture="['.event-block__warp', clickTexts2]"
v-delegate:click-c.left.capture="['.event-block__inner i', clickTexts3]"
v-delegate:click-d.left.once="['.event-block__inner i', clickTexts4]">
<div v-for="item in texts" :key="item" class="event-block__warp" :index-data="item">
<div class="event-block" v-text="item"></div>
<div class="event-block__inner">
<i v-text="`inner-${item}`" :index-data="`inner-${item}`"></i>
</div>
</div>
</div>
<button @click="show = false">hidden the list</button>
<button @click="trigger">trigger native event</button>
</main>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { DelegateEvent } from '../types';
@Component
export default class App extends Vue {
show = true;
texts = ['mouse-01', 'mouse-02', 'mouse-03', 'mouse-04', 'mouse-05'];
clickTexts1(e: DelegateEvent) {
console.log(e.currentTarget.getAttribute('index-data') + ', 冒泡');
}
clickTexts2(e: DelegateEvent) {
console.log(e.currentTarget.getAttribute('index-data') + ', 捕获');
}
clickTexts3(e: DelegateEvent) {
console.log(e.currentTarget.getAttribute('index-data') + ', 捕获');
}
clickTexts4(e: DelegateEvent) {
console.log('once event');
}
trigger() {
const elem = document.querySelector('.event-block__inner i') as HTMLElement;
this.trigger$Event(elem, 'click');
}
};
</script>
<style scoped>
.main__warp {
display: flex;
}
.event-block__warp {
width: 100px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
margin: 10px;
border: 2px solid #888;
flex-direction: column;
}
</style>