search-bar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view>
  3. <uni-card :is-shadow="false" is-full>
  4. <text class="uni-h6">搜索栏组件,通常用于搜索商品、文章等。</text>
  5. </uni-card>
  6. <uni-section title="基本用法" type="line">
  7. <uni-search-bar @confirm="search" :focus="true" v-model="searchValue" @blur="blur" @focus="focus" @input="input"
  8. @cancel="cancel" @clear="clear">
  9. </uni-search-bar>
  10. <view class="search-result">
  11. <text class="search-result-text">当前输入为:{{ searchValue }}</text>
  12. </view>
  13. </uni-section>
  14. <uni-section title="自定义样式" subTitle="使用 bgColor 属性自定义背景色" type="line">
  15. <uni-search-bar placeholder="自定义背景色" bgColor="#EEEEEE" @confirm="search" />
  16. </uni-section>
  17. <uni-section title="自定义icon" type="line">
  18. <uni-search-bar placeholder="自定义searchIcon" @confirm="search" @cancel="cancel" cancel-text="cancel">
  19. <uni-icons slot="searchIcon" color="#999999" size="18" type="home" />
  20. </uni-search-bar>
  21. </uni-section>
  22. <uni-section title="控制清除/取消按钮" subTitle="使用 clearButton 属性设置清除按钮" type="line">
  23. <uni-search-bar radius="5" placeholder="一直显示" clearButton="always" cancelButton="always" @confirm="search"
  24. @cancel="cancel" />
  25. <uni-search-bar class="uni-mt-10" radius="5" placeholder="自动显示隐藏" clearButton="auto" cancelButton="none" @confirm="search" />
  26. <uni-search-bar class="uni-mt-10" radius="100" placeholder="一直不显示" clearButton="none" cancelButton="none" @confirm="search" />
  27. </uni-section>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. searchValue: '123123'
  35. }
  36. },
  37. methods: {
  38. search(res) {
  39. uni.showToast({
  40. title: '搜索:' + res.value,
  41. icon: 'none'
  42. })
  43. },
  44. input(res) {
  45. console.log('----input:', res)
  46. },
  47. clear(res) {
  48. uni.showToast({
  49. title: 'clear事件,清除值为:' + res.value,
  50. icon: 'none'
  51. })
  52. },
  53. blur(res) {
  54. uni.showToast({
  55. title: 'blur事件,输入值为:' + res.value,
  56. icon: 'none'
  57. })
  58. },
  59. focus(e) {
  60. uni.showToast({
  61. title: 'focus事件,输出值为:' + e.value,
  62. icon: 'none'
  63. })
  64. },
  65. cancel(res) {
  66. uni.showToast({
  67. title: '点击取消,输入值为:' + res.value,
  68. icon: 'none'
  69. })
  70. }
  71. },
  72. onBackPress() {
  73. // #ifdef APP-PLUS
  74. plus.key.hideSoftKeybord();
  75. // #endif
  76. }
  77. }
  78. </script>
  79. <style lang="scss">
  80. .search-result {
  81. padding-top: 10px;
  82. padding-bottom: 20px;
  83. text-align: center;
  84. }
  85. .search-result-text {
  86. text-align: center;
  87. font-size: 14px;
  88. color:#666;
  89. }
  90. .example-body {
  91. /* #ifndef APP-NVUE */
  92. display: block;
  93. /* #endif */
  94. padding: 0px;
  95. }
  96. .uni-mt-10 {
  97. margin-top: 10px;
  98. }
  99. </style>