db-search.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view class="db-search">
  3. <input
  4. class="db-search__input"
  5. type="text"
  6. :value="modelValue"
  7. :placeholder="placeholder"
  8. confirm-type="search"
  9. @input="onInput"
  10. @confirm="onConfirm"
  11. />
  12. <text v-if="modelValue" class="db-search__clear" @click="onClear">清除</text>
  13. </view>
  14. </template>
  15. <script setup>
  16. const props = defineProps({
  17. modelValue: { type: String, default: '' },
  18. placeholder: { type: String, default: '搜索' }
  19. })
  20. const emit = defineEmits(['update:modelValue', 'search', 'clear', 'change'])
  21. function onInput(e) {
  22. const v = e.detail.value
  23. emit('update:modelValue', v)
  24. emit('change', v)
  25. }
  26. function onConfirm() {
  27. emit('search', props.modelValue)
  28. }
  29. function onClear() {
  30. emit('update:modelValue', '')
  31. emit('change', '')
  32. emit('clear')
  33. }
  34. </script>
  35. <style scoped>
  36. .db-search {
  37. display: flex;
  38. align-items: center;
  39. gap: 8px;
  40. background: #f7f8fa;
  41. border-radius: 8px;
  42. padding: 8px 12px;
  43. }
  44. .db-search__input {
  45. flex: 1;
  46. font-size: 14px;
  47. color: #323233;
  48. }
  49. .db-search__clear {
  50. font-size: 12px;
  51. color: #52b788;
  52. }
  53. </style>