背景:移动端需要和pc端select多选相对应,但是并没有现成的组件,vant只提供了picker选择器可以实现单选效果,所以需要自己封装组件
方法:把cell单元格和checkbox复选框结合,实现多选效果
代码(js代码根据需要去写就可以啦)
<van-popup
v-model="showPicker"
:value="true"
@close="closePopup"
position="bottom"
:style="{ height: '60%' }"
>
<van-search
:placeholder="placeholder"
v-model="searchData"
@search="getColumnList()"
@input="getColumnList()"
@clear="getColumnList()"
></van-search>
<!-- v-model="checkedValue" -->
<van-checkbox-group
ref="checkboxGroup"
@change="change"
v-model="checkedValue"
>
<van-cell-group>
<van-cell
v-for="(item, index) in list"
clickable
:key="item.specificEventId"
:title="item.specificEventName"
@click="toggle(index)"
>
<template #right-icon>
<van-checkbox :name="item" ref="checkboxes" shape="square" />
</template>
</van-cell>
</van-cell-group>
</van-checkbox-group>
</van-popup>