diff --git a/src/components/scContextmenu/index.vue b/src/components/scContextmenu/index.vue index 8e1c8f02..7f0a72e4 100644 --- a/src/components/scContextmenu/index.vue +++ b/src/components/scContextmenu/index.vue @@ -1,10 +1,10 @@ @@ -34,17 +34,10 @@ }, watch: { visible(value) { - var _this = this; - var cm = function(e){ - let sp = _this.$refs.contextmenu - if(sp&&!sp.contains(e.target)){ - _this.closeMenu() - } - } if (value) { - document.body.addEventListener('click', e=>cm(e)) + document.body.addEventListener('click', this.cm, true) }else{ - document.body.removeEventListener('click', e=>cm(e)) + document.body.removeEventListener('click', this.cm, true) } } }, @@ -52,6 +45,12 @@ }, methods: { + cm(e){ + let sp = this.$refs.contextmenu + if(sp&&!sp.contains(e.target)){ + this.closeMenu() + } + }, menuClick(command){ this.closeMenu() this.$emit('command', command) @@ -89,7 +88,7 @@