v-search.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="v-search">
  3. <view class="search-wrap">
  4. <up-search
  5. placeholder="搜索品种"
  6. v-model="searchVal"
  7. @clear="clear"
  8. @custom="searchFun"
  9. @search="searchFun"
  10. :bgColor="'transparent'"
  11. :actionStyle="actionStyle"
  12. :inputStyle="inputStyle"
  13. ></up-search>
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. import {
  19. ref,
  20. computed
  21. } from "vue"
  22. const searchVal = ref('')
  23. // 通过 props 传递样式
  24. const actionStyle = computed(() => ({
  25. textAlign: 'center',
  26. lineHeight: '52rpx',
  27. borderRadius: '40rpx',
  28. fontSize: '28rpx',
  29. backgroundColor: '#FFD95E',
  30. margin: '6rpx 8rpx',
  31. width: '112rpx',
  32. height: '52rpx'
  33. }))
  34. const inputStyle = computed(() => ({
  35. backgroundColor: 'transparent'
  36. }))
  37. const searchFun = (e)=>{
  38. emit('searchCallback',e)
  39. }
  40. const clear = ()=>{
  41. emit('clearCallback')
  42. }
  43. const emit = defineEmits(['searchCallback','clearCallback'])
  44. </script>
  45. <style lang="scss" scoped>
  46. .v-search {
  47. display: flex;
  48. align-items: center;
  49. width: 100%;
  50. border: 2rpx solid #FFD95E;
  51. border-radius: 40rpx;
  52. .search-wrap {
  53. flex: 1;
  54. }
  55. .search-btn {
  56. text-align: center;
  57. line-height: 52rpx;
  58. border-radius: 40rpx;
  59. font-size: 28rpx;
  60. background-color: #FFD95E;
  61. margin: 6rpx 8rpx;
  62. width: 112rpx;
  63. height: 52rpx;
  64. }
  65. }
  66. </style>