wk-search-box.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="wk-search-box">
  3. <view class="search-box__body">
  4. <text class="wk wk-search search-box__body-icon" />
  5. <input
  6. ref="searchCore"
  7. v-model="searchKeyword"
  8. maxlength="50"
  9. placeholder-class="wk-placeholder"
  10. placeholder="请输入关键字"
  11. type="text"
  12. class="search-box__body-core">
  13. <text class="wk wk-close-fill search-box__body-clear" @click="searchKeyword = ''" />
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'WkSearchBox',
  20. data() {
  21. return {
  22. searchKeyword: '',
  23. timer: null
  24. }
  25. },
  26. watch: {
  27. searchKeyword(val) {
  28. if (this.timer) {
  29. clearTimeout(this.timer)
  30. this.timer = null
  31. }
  32. this.timer = setTimeout(() => {
  33. clearTimeout(this.timer)
  34. this.timer = null
  35. this.$emit('search', val)
  36. }, 800)
  37. }
  38. }
  39. }
  40. </script>
  41. <style scoped lang="scss">
  42. .wk-search-box {
  43. padding: 20rpx 3%;
  44. .search-box__body {
  45. width: 100%;
  46. height: 66rpx;
  47. color: #999;
  48. background-color: white;
  49. border-radius: 15rpx;
  50. padding: 0 20rpx;
  51. @include center;
  52. .search-box__body-icon {
  53. font-size: 30rpx;
  54. color: #aaa;
  55. margin-right: 15rpx;
  56. }
  57. .search-box__body-core {
  58. flex: 1;
  59. height: 100%;
  60. font-size: 28rpx;
  61. color: $dark;
  62. }
  63. .search-box__body-clear {
  64. font-size: 28rpx;
  65. color: #cfcfcf;
  66. }
  67. }
  68. }
  69. </style>