index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view class="u-search">
  3. <view class="u-search-input">
  4. <van-search :value="searchKeyword" :placeholder="placeholder" use-action-slot class="van-search"
  5. @change="query" @search="onClickSearch">
  6. <view class="u-search-text" slot="action" @tap="onClickSearch">搜索</view>
  7. </van-search>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import VanSearch from '@/wxcomponents/vant/search/index'
  13. export default {
  14. options: {
  15. styleIsolation: 'shared'
  16. },
  17. components: {
  18. VanSearch
  19. },
  20. props: {
  21. value: String,
  22. placeholder: {
  23. type: String,
  24. default: ''
  25. }
  26. },
  27. computed: {},
  28. watch: {
  29. searchKeyword(val) {
  30. this.$emit('input', val)
  31. },
  32. value(val) {
  33. this.searchKeyword = this.value
  34. }
  35. },
  36. data() {
  37. return {
  38. searchKeyword: ''
  39. }
  40. },
  41. created() {
  42. this.searchKeyword = this.value
  43. },
  44. mounted() {},
  45. methods: {
  46. query(val) {
  47. this.searchKeyword = val
  48. this.$emit('input', this.searchKeyword)
  49. this.$emit('change', {
  50. detail: this.searchKeyword
  51. })
  52. },
  53. onClickSearch() {
  54. this.$emit('search')
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="scss">
  60. .u-search {
  61. .u-search-input {
  62. height: 64rpx;
  63. border-radius: 50rpx;
  64. background-color: #FFFFFF;
  65. box-shadow: 0 4rpx 4rpx 0 rgba(0, 0, 0, 0.15);
  66. border: 2rpx solid #D9D9D9;
  67. padding: 4rpx;
  68. overflow: hidden;
  69. .van-field__placeholder {
  70. font-size: $fontSize2;
  71. }
  72. .van-cell__left-icon-wrap {
  73. height: 50rpx;
  74. }
  75. .van-field__control {
  76. font-size: $fontSize2;
  77. height: 50rpx;
  78. }
  79. }
  80. .van-search {
  81. --search-padding: 0rpx;
  82. --search-input-height: 34rpx;
  83. --search-background-color: #FFFFFF;
  84. padding-right: 24rpx;
  85. font-size: $fontSize2;
  86. }
  87. .u-search-text {
  88. margin-left: 10rpx;
  89. font-size: $fontSize2;
  90. }
  91. .van-search__action {
  92. color: #333333;
  93. }
  94. .van-icon {
  95. color: #D4D4D6;
  96. }
  97. .van-cell {
  98. padding: 2rpx 0rpx 2rpx !important;
  99. }
  100. }
  101. </style>