zebra-ui基于uniapp,跨多端组件库
  • 2.x
  • 中文
开发指南
介绍
快速上手
进阶用法
常见问题
更新日志
贡献指南
国际化
基础组件
Button 按钮
Cell 单元格
ConfigProvider 全局配置
Icon 图标
Image 图片
Layout 布局
Popup 弹出层
Style 内置样式
Transition 动画
Toast 轻提示
表单组件
Area 省市区选择
Calendar 日历
Cascader 级联选择
Checkbox 复选框
DatePicker 日期选择
Field 输入框
Form 表单
NumberKeyboard 数字键盘
PasswordInput 密码输入框
Picker 选择器
PickerGroup 选择器组
Radio 单选框
Rate 评分
Search 搜索
Slider 滑块
Signature 签名
Stepper 步进器
Switch 开关
TimePicker 时间选择
Uploader 文件上传
反馈组件
ActionSheet 动作面板
Barrage 弹幕
Dialog 弹出框
DropdownMenu 下拉菜单
FloatingPanel 浮动面板
FloatingBubble 浮动气泡
Loading 加载
Notify 消息通知
Overlay 遮罩层
PullRefresh 下拉刷新
ShareSheet 分享面板
SwipeCell 滑动单元格
展示组件
Badge 徽标
Circle 环形进度条
Collapse 折叠面板
CountDown 倒计时
Divider 分割线
Empty 空状态
Highlight 高亮文本
List 列表
NoticeBar 通知栏
Popover 气泡弹出框
Progress 进度条
RollingText 翻滚文本
Skeleton 骨架屏
Steps 步骤条
Sticky 粘性布局
Swipe 轮播
Tag 标签
TextEllipsis 文本省略
Watermark 水印
导航组件
Grid 宫格
NavBar 导航栏
Sidebar 侧边导航
Tab 标签页
Tabbar 标签栏
TreeSelect 分类选择

Search Search

introduce

Input box component for search scenarios.

Code Demo

Basic usage

v-model is used to control the text in the search box, and background can customize the external background color of the search box.

<z-search v-model="value" placeholder="请输入搜索关键词" />
import { ref } from 'vue';
const value = ref('');

Event monitoring

The Search component provides search and cancel events. The search event is triggered after clicking the search/enter button on the keyboard, and the cancel event is triggered when the cancel button on the right side of the search box is clicked.

<z-search
v-model="value"
show-action
placeholder="Please enter search keywords"
@search="onSearch"
@cancel="onCancel"
/>

Search box content alignment

Set the alignment of the search box content through the input-align attribute. The optional values are center and right.

<z-search
v-model="value"
placeholder="Please enter search keywords"
input-align="center"
/>

Disable search box

Disable the search box via the disabled attribute.

<z-search v-model="value" disabled placeholder="请输入搜索关键词" />

Custom background color

The background color outside the search box can be set through the background attribute, and the shape of the search box can be set through the shape attribute. The optional value is round.

<z-search
v-model="value"
shape="round"
background="#4fc08d"
placeholder="Please enter search keywords"
/>

Custom buttons

Use the action slot to customize the content of the right button. After using the slot, the cancel event will no longer fire.

<z-search
v-model="value"
show-action
label="address"
placeholder="Please enter search keywords"
@search="onSearch"
>
<template #action>
<div @click="onClickButton">Search</div>
</template>
</z-search>

API

Props

ParametersDescriptionTypeDefault value
v-modelCurrent input valuenumber | string-
labelText on the left side of the search boxstring-
nameName, used as an identifier when submitting the formstring-
shapeSearch box shape, optional value is roundstringsquare
backgroundSearch box external background colorstring#f2f2f2
maxlengthMaximum number of characters enterednumber | string-
placeholderplaceholder textstring-
clearableWhether to enable the clear icon. Clicking the clear icon will clear the input boxbooleantrue
clear-iconClear the icon name or image link, which is equivalent to the name attribute of the Icon componentstringclear
clear-triggerThe timing of displaying the clear icon, always means it will be displayed when the input box is not empty,
focus means it will be displayed when the input box is focused and not empty
stringfocus
show-actionWhether to display the cancel button on the right side of the search boxbooleanfalse
action-textCancel button textstringCancel
disabledWhether to disable the input boxbooleanfalse
readonlyWhether to set the input box to read-only status. Content cannot be entered in read-only statusbooleanfalse
errorWhether to mark the input content in redbooleanfalse
error-messageBottom error message text, will not be displayed if emptystring-
formatterInput content formatting function(val: string) => string-
format-triggerThe timing when the format function is triggered, the optional value is onBlurstringonChange
input-alignInput box content alignment, optional values are center rightstringleft
left-iconThe icon name or image link on the left side of the input box, which is equivalent to the name attribute of the Icon componentstringsearch
right-iconThe icon name or image link on the right side of the input box, which is equivalent to the name attribute of the Icon componentstring-

Events

Event nameDescriptionCallback parameters
searchTriggered when search is determinedvalue: string (currently entered value)
update:model-valueTriggered when the content of the input box changesvalue: string (currently entered value)
focusTriggered when the input box gains focusevent: Event
blurTriggered when the input box loses focusevent: Event
click-inputTriggered when the input area is clickedevent: MouseEvent
click-left-iconTriggered when the left icon is clickedevent: MouseEvent
click-right-iconTriggered when the right icon is clickedevent: MouseEvent
clearTriggered after clicking the clear buttonevent: MouseEvent
cancelTriggered when the cancel button is clicked-

method

Through ref, you can get the Search instance and call the instance method.

Method nameDescriptionParametersReturn value
focusGet input box focus--
blurCancel focus of input box--

Slots

NameDescription
leftCustomize the content on the left (outside the search box)
actionCustomize the content on the right (outside the search box) and display it after setting the show-action attribute
labelCustomize the left text (in the search box)
left-iconCustomize the left icon (in the search box)
right-iconCustomize the right icon (in the search box)

Theme customization

Style variables

The component provides the following CSS variables, which can be used to customize styles. For usage, please refer to ConfigProvider component.

NameDefaultDescription
--z-search-padding20rpx var(--z-padding-sm)-
--z-search-backgroundvar(--z-background-2)-
--z-search-content-backgroundvar(--z-gray-1)-
--z-search-input-height68rpx-
--z-search-label-padding0 10rpx-
--z-search-label-colorvar(--z-text-color)-
--z-search-label-font-sizevar(--z-font-size-md)-
--z-search-left-icon-colorvar(--z-gray-6)-
--z-search-action-padding0 var(--z-padding-xs)-
--z-search-action-text-colorvar(--z-text-color)-
--z-search-action-font-sizevar(--z-font-size-md)-