headerInput.vue 990 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="container">
  3. <uni-icons type="search" size="24" color="#808080"></uni-icons>
  4. <input class="input" type="text" :placeholder="placeholder" placeholder-style="color:#CCCCCC;font-size:28rpx" @input="handleInput" />
  5. </view>
  6. </template>
  7. <script setup>
  8. import { ref } from 'vue'
  9. defineProps({
  10. placeholder: {
  11. type: String,
  12. default: '请输入关键词'
  13. }
  14. })
  15. const $emit = defineEmits(['changeInputValue'])
  16. const timer = ref(null)
  17. const handleInput = (e) => {
  18. if (timer.value) {
  19. clearTimeout(timer.value)
  20. }
  21. timer.value = setTimeout(() => {
  22. $emit('changeInputValue', e.detail.value)
  23. }, 500)
  24. }
  25. </script>
  26. <style lang="scss" scoped>
  27. .container {
  28. position: relative;
  29. display: flex;
  30. align-items: center;
  31. box-sizing: border-box;
  32. padding: 0 40rpx;
  33. margin-top: 30rpx;
  34. width: 710rpx;
  35. height: 100rpx;
  36. border-radius: 80rpx;
  37. border: 1rpx solid #ccc;
  38. background-color: #fff;
  39. .input {
  40. margin-left: 16rpx;
  41. width: 100%;
  42. height: 100%;
  43. }
  44. }
  45. </style>