使用场景:
产品要求需要下拉选择,并且可以搜索对应的值,针对移动端没有类似的案例,因此vant+uni-app相结合,实现了可搜索的popup,具体代码如下:
dom解构
<template>
<!-- uni-app结合vant组件库,实现可搜索的弹层,只能单选 -->
<view class="popup-vant-select" @click.prevent="handleOpen">
<!-- :class="{ open: popupOpenFlag, clear: (props.clear && selectLabel) }" -->
<text
class="icon"
:class="{ open: popupOpenFlag, clear: props.clear && selectLabel }"
@click.stop="handleClear"
></text>
<!-- 下拉框中显示默认的值 -->
<view v-if="!selectLabel" class="placeholder">{
{ props.placeholder }}</view>
<!-- 下拉框中显示选择的值 -->
<view v-else>{
{ selectLabel }}</view>
<uni-popup ref="popupRef" type="bottom" background-color="#fff" :is-mask-click="false">
<view class="select-box">
<view v-if="props.title" class="title">这里可以设置标题</view>
<view class="btn-box">
<text class="cancel" @click="handleCancel">取消</text>
<text class="confirm" @click="handleConfirm">确定</text>
</view>
<CommonSearch
v-if="props.filterable"
@input="hanndleInput"
placeholder="请输入"
background="#fff"
/>
<!-- option-height:选项高度;visible-option-num:可见的选项个数 -->
<Picker
:show-toolbar="false"
v-model="selectValue"
:columns="list"
option-height="40rpx"
visible-option-num="4"
:columns-fi