dropdown.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <u-overlay :show="isShow" @click="isShow = false" opacity="0">
  3. <view :class="'k-' + position" :style="[myStyle]">
  4. <slot/>
  5. </view>
  6. </u-overlay>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. top: {
  12. type: [String, Number],
  13. default: 0,
  14. },
  15. position: {
  16. type: String,
  17. default: 'right',//left
  18. },
  19. left: {
  20. type: [String, Number],
  21. default: 0,
  22. },
  23. right: {
  24. type: [String, Number],
  25. default: 0,
  26. },
  27. },
  28. computed: {
  29. myStyle() {
  30. return {
  31. marginTop: this.$u.addUnit(this.top, 'px'),
  32. marginLeft: this.$u.addUnit(this.left, 'px'),
  33. marginRight: this.$u.addUnit(this.right, 'px'),
  34. }
  35. },
  36. },
  37. data() {
  38. return {
  39. isShow: false,
  40. }
  41. },
  42. methods: {
  43. show() {
  44. this.isShow = true
  45. },
  46. hide() {
  47. this.isShow = false
  48. },
  49. },
  50. }
  51. </script>
  52. <style>
  53. .k-top {
  54. background-color: #333333;
  55. width: fit-content;
  56. }
  57. .k-left {
  58. display: flex;
  59. flex-direction: row;
  60. justify-content: flex-start;
  61. }
  62. .k-right {
  63. display: flex;
  64. flex-direction: row;
  65. justify-content: flex-end;
  66. }
  67. </style>