DropdownMenu.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="dropdown-container">
  3. <view class="dropdown-trigger" @tap="toggleDropdown">
  4. <text class="fa fa-ellipsis-h"></text>
  5. </view>
  6. <view class="dropdown-menu" v-if="show">
  7. <view
  8. v-for="(item, index) in options"
  9. :key="index"
  10. class="dropdown-item"
  11. @tap="handleSelect(item)"
  12. >
  13. {{ item.label }}
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'DropdownMenu',
  21. props: {
  22. options: {
  23. type: Array,
  24. default: () => []
  25. }
  26. },
  27. data() {
  28. return {
  29. show: false
  30. }
  31. },
  32. methods: {
  33. toggleDropdown() {
  34. this.show = !this.show
  35. },
  36. handleSelect(item) {
  37. this.$emit('select', item)
  38. this.show = false
  39. }
  40. }
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. .dropdown-container {
  45. position: relative;
  46. .dropdown-trigger {
  47. padding: 10rpx;
  48. cursor: pointer;
  49. }
  50. .dropdown-menu {
  51. position: absolute;
  52. top: 100%;
  53. right: 0;
  54. background: #fff;
  55. border-radius: 8rpx;
  56. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1);
  57. z-index: 100;
  58. min-width: 200rpx;
  59. .dropdown-item {
  60. padding: 20rpx 30rpx;
  61. font-size: 28rpx;
  62. color: #333;
  63. text-align: center;
  64. &:hover {
  65. background: #f5f5f5;
  66. }
  67. }
  68. }
  69. }
  70. </style>