Search.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="search-container van-fade-an">
  3. <div class="click-pop" v-if="type === 'click'" @click="onClick"></div>
  4. <van-search @input="$emit('input', $event)" @search="onSearch" class="my-search" left-icon="diy-search" v-model.trim="input" placeholder="搜索文档" />
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { Component, Vue, Prop } from 'vue-property-decorator'
  9. import { Icon, Search } from 'vant'
  10. // @ is an alias to /src
  11. @Component({
  12. name: 'Search',
  13. components: {
  14. [Search.name]: Search,
  15. [Icon.name]: Icon
  16. }
  17. })
  18. export default class Empty extends Vue {
  19. @Prop({ default: 'input' }) type?: string | undefined;
  20. @Prop({ default: '' }) defalultValue?: string | undefined;
  21. input = ''
  22. created () {
  23. this.input = this.defalultValue || ''
  24. }
  25. onSearch () {
  26. this.$emit('submit', this.input)
  27. }
  28. onClick () {
  29. if (this.type === 'click') {
  30. this.$emit('click')
  31. }
  32. }
  33. }
  34. </script>
  35. <style scoped lang="scss">
  36. @keyframes show {
  37. to {
  38. opacity: 1;
  39. }
  40. }
  41. .van-fade-an {
  42. opacity: 0;
  43. animation: show 1s 300ms ease forwards;
  44. z-index: 666;
  45. position: relative;
  46. }
  47. .click-pop {
  48. position: absolute;
  49. width: 100%;
  50. height: 100%;
  51. z-index: 99;
  52. opacity: 0;
  53. }
  54. .search-container {
  55. width: 100%;
  56. }
  57. .my-search {
  58. &::v-deep.van-search {
  59. padding: 7px 16px;
  60. .van-search__content {
  61. border-radius: 8px;
  62. background: #F5F6F7;
  63. border: 1px solid rgba(0, 0, 0, 0.05);
  64. }
  65. .van-cell {
  66. align-items: center;
  67. height: 38px;
  68. }
  69. .van-field__left-icon {
  70. height: 20px;
  71. margin-right: 8px;
  72. }
  73. .van-field__control {
  74. color: #171826;
  75. font-family: PingFang SC;
  76. font-size: 14px;
  77. letter-spacing: 0px;
  78. text-align: left;
  79. }
  80. }
  81. @include diy-icon('search', 20, 20)
  82. }
  83. </style>