searchBox.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view>
  3. <!-- 搜索 -->
  4. <view class="searchBox">
  5. <image src="../../static/img/icon_search.png" class="searchImg"></image>
  6. <input type="text" class="searchInput" :placeholder='placeholder' v-model="inputValue"
  7. @confirm="search" />
  8. <image src="../../static/img/icon_close.png" class="searchClose" v-if="inputValue!=''"
  9. @click="clear"></image>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "searchBox",
  16. props: {
  17. placeholder: {
  18. type: String,
  19. default: '请输入搜索内容'
  20. },
  21. },
  22. data() {
  23. return {
  24. inputValue: '',
  25. };
  26. },
  27. methods:{
  28. search(){
  29. if (!this.inputValue) return;
  30. //console.log(this.inputValue);
  31. this.$emit('search',this.inputValue);
  32. },
  33. clear(){
  34. this.inputValue = ''
  35. this.$emit('search','');
  36. },
  37. }
  38. }
  39. </script>
  40. <style>
  41. .searchBox {
  42. height: 72rpx;
  43. margin: 24rpx;
  44. background-color: #F4F5F7;
  45. border-radius: 36rpx;
  46. display: flex;
  47. position: relative;
  48. }
  49. .searchImg {
  50. margin-top: 20rpx;
  51. margin-left: 20rpx;
  52. width: 32rpx;
  53. height: 32rpx;
  54. }
  55. .searchInput {
  56. height: 72rpx;
  57. font-size: 28rpx;
  58. padding-left: 16rpx;
  59. width: 78%;
  60. }
  61. .searchClose {
  62. position: absolute;
  63. width: 36rpx;
  64. height: 36rpx;
  65. right: 36rpx;
  66. top: 20rpx;
  67. }
  68. </style>