anji-contextMenu.vue 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!--
  2. * @Descripttion: 右键菜单
  3. * @version:
  4. * @Author: qianlishi
  5. * @Date: 2021-10-21 15:52:03
  6. * @LastEditors: qianlishi
  7. * @LastEditTime: 2021-10-21 19:40:05
  8. -->
  9. <template>
  10. <div v-show="visible" class="contentmenu" :style="styleObj">
  11. <slot />
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. styleObj: Object,
  18. visible: Boolean,
  19. },
  20. data() {
  21. return {}
  22. },
  23. watch: {
  24. visible(value) {
  25. if (value) {
  26. document.body.addEventListener('click', this.closeMenu)
  27. } else {
  28. document.body.removeEventListener('click', this.closeMenu)
  29. }
  30. },
  31. },
  32. methods: {
  33. closeMenu() {
  34. this.$emit('update:visible', false)
  35. },
  36. },
  37. }
  38. </script>
  39. <style lang="scss" scoped>
  40. .contentmenu {
  41. position: fixed;
  42. z-index: 99999;
  43. list-style: none;
  44. -webkit-box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  45. box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  46. padding: 0;
  47. background: #fff;
  48. cursor: pointer;
  49. }
  50. </style>