搜索栏 SearchBar

基本用法

搜索栏组件 SearchBar - 图1

  1. <template lang="html">
  2. <div>
  3. <div class="demo-hidden">
  4. <za-panel>
  5. <za-panel-header title="基本"></za-panel-header>
  6. <za-panel-body>
  7. <za-search-bar placeholder="搜索"
  8. cancelText="取消"
  9. :showCancel="false"
  10. @change="handleChange"
  11. @submit="handleSubmit"
  12. @blur="handleBlur"
  13. @focus="handleFocus"
  14. @clear="handleClear"
  15. @cancel="handleCancel"
  16. ></za-search-bar>
  17. </za-panel-body>
  18. </za-panel>
  19. <za-panel>
  20. <za-panel-header title="始终展示取消按钮"></za-panel-header>
  21. <za-panel-body>
  22. <za-search-bar placeholder="搜索"
  23. shape="round"
  24. cancelText="取消"
  25. :showCancel="true"
  26. value="默认搜索关键字"
  27. ></za-search-bar>
  28. </za-panel-body>
  29. </za-panel>
  30. <za-panel>
  31. <za-panel-header title="手动获取焦点"></za-panel-header>
  32. <za-panel-body>
  33. <za-search-bar ref="searchRef" placeholder="搜索" shape="radius"
  34. cancelText="取消" ></za-search-bar>
  35. <za-button theme='primary' @click="handleClick">点击获取焦点</za-button>
  36. </za-panel-body>
  37. </za-panel>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. value: "",
  46. }
  47. },
  48. methods: {
  49. handleClick(){
  50. this.$refs.searchRef.focus();
  51. },
  52. handleChange(val){
  53. this.value = val
  54. },
  55. handleSubmit(val){
  56. console.log(`搜索内容为${val}`);
  57. },
  58. handleChange(val){
  59. console.log(`搜索内容为${val}`);
  60. },
  61. handleFocus(){
  62. console.log('获取焦点');
  63. },
  64. handleBlur(){
  65. console.log('失去焦点');
  66. },
  67. handleClear(){
  68. console.log('点击了清除');
  69. },
  70. handleCancel(){
  71. console.log('点击了取消');
  72. }
  73. },
  74. };
  75. </script>

API

SearchBar Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-search-bar类名前缀
placeholderstringtextplaceholder
disabledboolfalse是否禁用
valuestring, number搜索关键字
shapestring形状,round,radius
cancelTextstring'取消'取消文本
showCancelboolfalse是否显示取消操作
clearableboolfalse是否可以清除操作

SearchBar Events

事件名称说明回调参数
change当绑定值变化时触发的事件最新的值
focus当获取焦点时触发的事件
blur当失去焦点时触发的事件
clear当绑定值被清除时触发的事件最新的值
cancel当取消操作时触发的事件
submit当绑定值变化时触发的Form搜索事件最新的值