searchBox.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view>
  3. <!-- 搜索 -->
  4. <view class="searchBox">
  5. <image src="../../static/mobile/icon_search@2x.png" class="searchImg"></image>
  6. <input type="text" class="searchInput" :placeholder='placeholder' v-model="inputValue"
  7. @confirm="search" />
  8. <image src="../../static/mobile/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 0;
  44. background-color: #FFFFFF;
  45. border-radius: 36rpx;
  46. border: #FF4F00 3rpx solid;
  47. display: flex;
  48. position: relative;
  49. }
  50. .searchImg {
  51. margin-top: 20rpx;
  52. margin-left: 20rpx;
  53. width: 32rpx;
  54. height: 32rpx;
  55. }
  56. .searchInput {
  57. height: 72rpx;
  58. font-size: 28rpx;
  59. padding-left: 16rpx;
  60. width: 78%;
  61. }
  62. .searchClose {
  63. position: absolute;
  64. width: 36rpx;
  65. height: 36rpx;
  66. right: 36rpx;
  67. top: 20rpx;
  68. }
  69. </style>