<template>
  <div
    v-if="showMenu"
    class="menu_style"
    :style="{top:y+'px',left:x+'px'}"
  >
    <ul>
      <!-- 分别传递事件给父元素调用 -->
      <!-- <li @click="()=>{$emit('open')}">打开</li> -->
      <!-- <li @click="()=>{$emit('update')}">编辑</li> -->
      <li @click="()=>{$emit('del')}">
        <i class="el-icon-delete" />&nbsp;&nbsp;
        <span>删 除</span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: 'RightMenu',
  props: {
    x: {
      type: [Number],
      default: 0
    },
    y: {
      type: [Number],
      default: 0
    },
    showMenu: {
      type: [Boolean],
      default: false
    }
  },
  mounted() {
    // 监听body上的点击
    document.querySelector('body').addEventListener('click', this.closeMenu)
  },
  beforeDestroy() {
    // 移除监听
    document.querySelector('body').removeEventListener('click', this.closeMenu)
  },
  methods: {
    // 点击别处时隐藏目录，并传递一个关闭事件
    closeMenu(e) {
      this.$emit('update:showMenu', false)
      this.$emit('close', false)
    }
  }
}
</script>
<style scoped>
	.menu_style{
		position: absolute;
		width: 100px;
		background-color: #fff;
		border-radius: 2px;
		box-shadow: 2px 2px 14px #d0d0d0;
  }
  ul{
    margin: 0;
    padding: 0;
  }
	.menu_style>ul>li{
    list-style: none;
    height: 38px;
    text-align: center;
		line-height: 38px;
		border-bottom: 1px dashed #f0f0f0;
    cursor: pointer;
	}
	.menu_style>ul>li:hover{
		background: #E0EEFF;
	}
</style>
