You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.0 KiB
2.0 KiB
代码演示
基础用法
v-model
用于控制搜索框中的内容,placeholder
控制搜索框占位提示文字。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字"></hd-search-bar>
const keyword = ref<string>('')
禁用搜索框
通过disabled
属性决定是否禁用搜索框,默认不禁用。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字" :disabled="true"></hd-search-bar>
const keyword = ref<string>('')
清空搜索框内容
通过clearable
属性决定搜索框内容是否可以点击清空,默认存在点击清空按钮。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字" :clearable="false"></hd-search-bar>
const keyword = ref<string>('')
取消按钮
通过showCancel
属性决定是否显示取消按钮,默认显示取消。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字" :showCancel="false"></hd-search-bar>
const keyword = ref<string>('')
事件监听
当点击键盘搜索或回车按钮后触发confirm
事件;当点击清空按钮后触发clear
事件;在showCancel
为true
时,点击取消后触发cancel
事件。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字" @confirm="doConfirm" @cancel="doCancel" @clear="doClear"></hd-search-bar>
const keyword = ref<string>('')
function doConfirm(e) {
console.log(e)
}
function doCancel(e) {
this.keyword = ''
uni.navigateBack({
delta: 1
})
}
function doClear() {
this.keyword = ''
}
自定义输入框头部或尾部内容
使用prefix
插槽可以自定义输入框头部内容,使用suffix
插槽可以自定义输入框尾部内容。
<hd-search-bar v-model="keyword" placeholder="请输入搜索关键字">
<view slot="prefix"></view>
<view slot="suffix"></view>
</hd-search-bar>
const keyword = ref<string>('')