My_search.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <view class="search-box">
  3. <view class="search">
  4. <icon class="icon" type="search" size="3.733vw" />
  5. <input v-model="value" class="input" confirm-type="search" placeholder-style="font-size:3.733vw;"
  6. :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. },
  23. data() {
  24. return {
  25. value: ""
  26. }
  27. },
  28. methods: {
  29. onConfirm() {
  30. this.$emit("onSearch", this.value)
  31. },
  32. onClear() {
  33. this.value = '';
  34. this.$emit("onSearch", this.value)
  35. }
  36. },
  37. }
  38. </script>
  39. <style lang="scss">
  40. .search-box {
  41. display: flex;
  42. width: 100%;
  43. box-sizing: border-box;
  44. .search {
  45. display: flex;
  46. align-items: center;
  47. flex: 1;
  48. height: 30px;
  49. background: #F2F2F2;
  50. border-radius: 50px;
  51. flex-shrink: 0;
  52. margin: 0 !important;
  53. .icon {
  54. padding: 10px;
  55. }
  56. .input {
  57. flex: 1;
  58. margin: 0 !important;
  59. }
  60. }
  61. }
  62. </style>