-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.vue
61 lines (58 loc) · 1.06 KB
/
index.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
<template>
<div
v-show="isVisible"
class="lil-context-menu"
:style="style"
tabindex="-1"
@blur="close"
@click="close"
@contextmenu.capture.prevent>
<slot :user-data="userData"></slot>
</div>
</template>
<script>
const Vue = require('vue')
module.exports = {
name: 'lil-context-menu',
data () {
return {
x: null,
y: null,
userData: null
}
},
computed: {
style () {
return this.isVisible ? {
top: this.y - document.body.scrollTop + 'px',
left: this.x + 'px'
} : {}
},
isVisible () {
return this.x !== null && this.y !== null
}
},
methods: {
open (evt, userData) {
this.x = evt.pageX || evt.clientX
this.y = evt.pageY || evt.clientY
this.userData = userData
Vue.nextTick(() => this.$el.focus())
},
close (evt) {
this.x = null
this.y = null
this.userData = null
}
}
}
</script>
<style scoped>
.lil-context-menu {
position: fixed;
z-index: 999;
}
.lil-context-menu:focus {
outline: none;
}
</style>