select.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view>
  3. <view class="select">
  4. <view class="slect_list" :style="'top:-' + (props.list.length) * 2.55 + 'em'">
  5. <view v-if="props.fOpen" :class="{list_item: true, list_item_act: props.fOpen}"
  6. v-for="(v,i) in props.list" :key="'select-'+ i" v-text="v.text" @click="()=>change(v)"></view>
  7. </view>
  8. <view class="text" v-text="props.btnText || '请选择'" @click="show"></view>
  9. </view>
  10. </view>
  11. </template>
  12. <script setup>
  13. import {
  14. defineProps,
  15. defineEmits,
  16. ref
  17. } from "vue";
  18. const props = defineProps({
  19. btnText: String,
  20. list: Array,
  21. url: String,
  22. fOpen: Boolean
  23. });
  24. const emits = defineEmits(['open', 'change']);
  25. function change(v) {
  26. emits("open");
  27. emits("change", v.value);
  28. }
  29. function show() {
  30. props.url ? emits('change', props.url) : emits('open');
  31. }
  32. </script>
  33. <style lang="scss">
  34. .select {
  35. position: relative;
  36. display: inline-block;
  37. width: 90%;
  38. margin: 0 .5em;
  39. text-align: center;
  40. border-radius: 5px;
  41. background-color: #b5bdc3;
  42. line-height: 2.5em;
  43. color: #fff;
  44. .slect_list {
  45. position: absolute;
  46. width: 100%;
  47. background-color: #b5bdc3;
  48. text-align: center;
  49. border-top-left-radius: 5px;
  50. border-top-right-radius: 5px;
  51. .list_item {
  52. line-height: 2.5em;
  53. text-align: center;
  54. height: 0;
  55. transition: all .2s;
  56. width: 100%;
  57. border-bottom: 1px solid #eee;
  58. }
  59. .list_item_act {
  60. height: 2.5em;
  61. }
  62. }
  63. }
  64. </style>