my-search.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view>
  3. <view class="my-search-container" :style="{'background-color': bgcolor}" @click="searchBoxHandler">
  4. <!-- 使用 view 组件模拟 input 输入框的样式 -->
  5. <view class="my-search-box" :style="{'border-radius': radius + 'px'}">
  6. <uni-icons type="search" size="17"></uni-icons>
  7. <text class="placeholder">搜索</text>
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name:"my-search",
  15. data() {
  16. return {
  17. };
  18. },
  19. props: {
  20. // 背景颜色
  21. bgcolor: {
  22. type: String,
  23. default: '#C00000'
  24. },
  25. // 圆角尺寸
  26. radius: {
  27. type: Number,
  28. // 单位是 px
  29. default: 18
  30. }
  31. },
  32. methods: {
  33. // 点击了模拟的 input 输入框
  34. searchBoxHandler() {
  35. // 触发外界通过 @click 绑定的 click 事件处理函数
  36. this.$emit('click')
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="scss">
  42. .my-search-container {
  43. // background-color: #c00000;
  44. height: 50px;
  45. padding: 0 10px;
  46. display: flex;
  47. align-items: center;
  48. }
  49. .my-search-box {
  50. height: 36px;
  51. background-color: #F2F2F4;
  52. border: 1px solid #ccc;
  53. // border-radius: 15px;
  54. width: 100%;
  55. display: flex;
  56. align-items: center;
  57. justify-content: center;
  58. .placeholder {
  59. font-size: 15px;
  60. margin-left: 5px;
  61. }
  62. }
  63. </style>