search-bar.nvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view>
  3. <uni-section title="基本用法" type="line"></uni-section>
  4. <view class="example-body">
  5. <uni-search-bar @confirm="search" @input="input" @cancel="cancel" />
  6. <view class="search-result">
  7. <text class="search-result-text">当前输入为:{{ searchVal }}</text>
  8. </view>
  9. </view>
  10. <uni-section title="自定义样式" type="line"></uni-section>
  11. <view class="example-body">
  12. <uni-search-bar placeholder="自定义placeholder" @confirm="search" />
  13. <uni-search-bar placeholder="自定义背景色" bgColor="#EEEEEE" @confirm="search" />
  14. <uni-search-bar radius="100" placeholder="自定义圆角" @confirm="search" />
  15. </view>
  16. <uni-section title="控制清除/取消按钮" type="line"></uni-section>
  17. <view class="example-body">
  18. <uni-search-bar radius="5" placeholder="一直显示" clearButton="always" cancelButton="always" @confirm="search" />
  19. <uni-search-bar radius="5" placeholder="自动显示隐藏" clearButton="auto" cancelButton="auto" @confirm="search" />
  20. <uni-search-bar radius="100" placeholder="一直不显示" clearButton="none" cancelButton="none" @confirm="search" />
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. components: {},
  27. data() {
  28. return {
  29. searchVal: ''
  30. }
  31. },
  32. methods: {
  33. search(res) {
  34. uni.showToast({
  35. title: '搜索:' + res.value,
  36. icon: 'none'
  37. })
  38. },
  39. input(res) {
  40. this.searchVal = res.value
  41. },
  42. cancel(res) {
  43. uni.showToast({
  44. title: '点击取消,输入值为:' + res.value,
  45. icon: 'none'
  46. })
  47. }
  48. },
  49. onBackPress() {
  50. // #ifdef APP-PLUS
  51. plus.key.hideSoftKeybord();
  52. // #endif
  53. }
  54. }
  55. </script>
  56. <style>
  57. @charset "UTF-8";
  58. /* 头条小程序组件内不能引入字体 */
  59. /* #ifdef MP-TOUTIAO */
  60. @font-face {
  61. font-family: uniicons;
  62. font-weight: normal;
  63. font-style: normal;
  64. src: url("~@/static/uni.ttf") format("truetype");
  65. }
  66. /* #endif */
  67. /* #ifndef APP-NVUE */
  68. page {
  69. display: flex;
  70. flex-direction: column;
  71. box-sizing: border-box;
  72. background-color: #efeff4;
  73. min-height: 100%;
  74. height: auto;
  75. }
  76. view {
  77. font-size: 14px;
  78. line-height: inherit;
  79. }
  80. .example {
  81. padding: 0 15px 15px;
  82. }
  83. .example-info {
  84. padding: 15px;
  85. color: #3b4144;
  86. background: #ffffff;
  87. }
  88. .example-body {
  89. /* #ifndef APP-NVUE */
  90. display: flex;
  91. /* #endif */
  92. flex-direction: row;
  93. flex-wrap: wrap;
  94. justify-content: center;
  95. padding: 0;
  96. font-size: 14px;
  97. background-color: #ffffff;
  98. }
  99. /* #endif */
  100. .example {
  101. padding: 0 15px;
  102. }
  103. .example-info {
  104. /* #ifndef APP-NVUE */
  105. display: block;
  106. /* #endif */
  107. padding: 15px;
  108. color: #3b4144;
  109. background-color: #ffffff;
  110. font-size: 14px;
  111. line-height: 20px;
  112. }
  113. .example-info-text {
  114. font-size: 14px;
  115. line-height: 20px;
  116. color: #3b4144;
  117. }
  118. .example-body {
  119. flex-direction: column;
  120. padding: 15px;
  121. background-color: #ffffff;
  122. }
  123. .word-btn-white {
  124. font-size: 18px;
  125. color: #FFFFFF;
  126. }
  127. .word-btn {
  128. /* #ifndef APP-NVUE */
  129. display: flex;
  130. /* #endif */
  131. flex-direction: row;
  132. align-items: center;
  133. justify-content: center;
  134. border-radius: 6px;
  135. height: 48px;
  136. margin: 15px;
  137. background-color: #007AFF;
  138. }
  139. .word-btn--hover {
  140. background-color: #4ca2ff;
  141. }
  142. .search-result {
  143. margin-top: 10px;
  144. margin-bottom: 20px;
  145. text-align: center;
  146. }
  147. .search-result-text {
  148. text-align: center;
  149. font-size: 14px;
  150. }
  151. .example-body {
  152. /* #ifndef APP-NVUE */
  153. display: block;
  154. /* #endif */
  155. padding: 0px;
  156. }
  157. </style>