My_search.vue 1.6 KB

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