vue-context-menu icon indicating copy to clipboard operation
vue-context-menu copied to clipboard

弹出菜单位置不对

Open jiawen-Bees360 opened this issue 6 years ago • 2 comments

感谢你的工作,但我发现有一点小问题,注意下方你的源码:你根据右键事件的clientX和clientY来直接设置menu的style的left和top,但是在一些布局中仅仅设置left和top根本无效,于是menu自始至终都会在文档流中的位置(而不是根据右键点击的位置改变)

    // 右键事件事件处理
    contextMenuHandler (e) {
      this.x = e.clientX
      this.y = e.clientY
      this.layout()
      this.$emit('update:show', true)
      e.preventDefault()
    },
    // 布局
    layout () {
      this.style = {
        left: this.x + 'px',
        top: this.y + 'px'
      }
    }

我加了一个position: absolute;,解决了我这边的问题,但不知道在别的布局方式中会不会有偏移。

jiawen-Bees360 avatar Apr 09 '18 08:04 jiawen-Bees360

好的,谢谢你的反馈,我会测试下不同的布局方式

binggg avatar Apr 09 '18 08:04 binggg

@binggg 我知道了,你的demo能work的原因在于你给组件加了一个.right-menu的class, 其中有position: fixed,或许可以把这个直接加到源码里面去。

.right-menu {
  position: fixed;
  background: #fff;
  border: solid 1px rgba(0, 0, 0, .2);
  border-radius: 3px;
  z-index: 999;
  display: none;
}

jiawen-Bees360 avatar Apr 09 '18 08:04 jiawen-Bees360