SearchBar.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view
  3. class="search-bar-container" :style="{
  4. height,
  5. borderColor: color,
  6. background
  7. }" @click="handleClick"
  8. >
  9. <BeeIcon :src="require('./search.png')"></BeeIcon>
  10. <input v-model="content" style="font-size: 24upx;" type="text" placeholder="输入您想搜索的商品" />
  11. <button class="bee-btn" :style="{ background: color }" @click="handleClickBtn">
  12. {{ btnText }}
  13. </button>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'SearchBar',
  19. props: {
  20. prevent: {
  21. type: Boolean,
  22. default: false
  23. },
  24. height: {
  25. type: String,
  26. default: '72upx'
  27. },
  28. color: {
  29. type: String,
  30. default: '#FA5151'
  31. },
  32. btnText: {
  33. type: String,
  34. default: '搜索'
  35. },
  36. background: {
  37. type: String
  38. }
  39. },
  40. data() {
  41. return {
  42. content: ''
  43. }
  44. },
  45. methods: {
  46. handleClick() {
  47. if (this.prevent) {
  48. this.$emit('click')
  49. }
  50. },
  51. handleClickBtn() {
  52. if (!this.prevent) {
  53. this.$emit('click-btn', this.content)
  54. }
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="less" scoped>
  60. .search-bar-container {
  61. display: flex;
  62. align-items: center;
  63. justify-content: flex-start;
  64. position: relative;
  65. border: 2upx solid #fa5151;
  66. padding: 16upx 122upx 16upx 16upx;
  67. box-sizing: border-box;
  68. border-radius: 100px;
  69. input {
  70. flex: 1;
  71. color: #999999;
  72. margin-left: 14upx;
  73. }
  74. .bee-btn {
  75. display: flex;
  76. align-items: center;
  77. justify-content: center;
  78. position: absolute;
  79. color: #f9f9f9;
  80. right: 0;
  81. top: -2upx;
  82. width: 120upx;
  83. height: 72upx;
  84. font-size: 28upx;
  85. border-radius: 100px;
  86. transition: all 350ms;
  87. &:active {
  88. opacity: 0.7;
  89. }
  90. }
  91. }
  92. </style>