My_search.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="search-box">
  3. <view class="search" :style="{ background: background || '#F2F2F2' }">
  4. <icon class="icon" type="search" size="3.733vw" />
  5. <input v-model="value" class="input" :disabled="disabled" confirm-type="search"
  6. placeholder-style="font-size:3.733vw;" :placeholder="placeholder" type="text"
  7. @input="isInput ? onConfirm($event) : ''" @confirm="isInput ? '' : onConfirm($event)">
  8. <icon v-if="value" class="icon" type="clear" size="3.733vw" @click="onClear" />
  9. </view>
  10. <slot />
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. placeholder: {
  17. type: String,
  18. default: "搜索关键字"
  19. },
  20. onSearch: {
  21. type: Function
  22. },
  23. disabled: {
  24. type: Boolean,
  25. default: false
  26. },
  27. background: {
  28. type: String
  29. },
  30. isInput: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data() {
  36. return {
  37. value: ""
  38. }
  39. },
  40. methods: {
  41. onConfirm() {
  42. this.$emit("onSearch", this.value)
  43. },
  44. onClear() {
  45. this.value = '';
  46. this.$emit("onSearch", this.value)
  47. }
  48. },
  49. }
  50. </script>
  51. <style lang="scss">
  52. .search-box {
  53. display: flex;
  54. width: 100%;
  55. box-sizing: border-box;
  56. .search {
  57. display: flex;
  58. align-items: center;
  59. flex: 1;
  60. height: 30px;
  61. border-radius: 50px;
  62. flex-shrink: 0;
  63. margin: 0 !important;
  64. .icon {
  65. padding: 10px;
  66. }
  67. .input {
  68. flex: 1;
  69. margin: 0 !important;
  70. }
  71. }
  72. }
  73. </style>