Skip to content

Picker 选择器

单列选择器

html
<vz-picker v-model="pickerValue" :data="listData" placeholder="请选择" border radius="20rpx"></vz-picker>
typescript
import { ref } from "vue";

const pickerValue = ref("");
const listData = ref(["A", "B", "C", "D", "E", "F", "G"]);

单列对象选择器

html
<vz-picker
  v-model="pickerValueObj"
  :data="listDataObj"
  :dataMap="{ value: 'id', label: 'name' }"
  placeholder="请选择"
  border
  radius="20rpx"
></vz-picker>
typescript
import { ref } from "vue";

const pickerValueObj = ref("");
const listDataObj = ref([
  { id: 1, name: "A" },
  { id: 2, name: "B" },
  { id: 3, name: "C" },
  { id: 4, name: "D" },
  { id: 5, name: "E" },
  { id: 6, name: "F" },
  { id: 7, name: "G" },
]);

多列选择器

html
<vz-picker v-model="pickerValueMulti" :data="listDataMulti" placeholder="请选择" border radius="20rpx"></vz-picker>
typescript
import { ref } from "vue";

const pickerValueMulti = ref([]);
const listDataMulti = ref([
  ["A", "B", "C", "D", "E", "F", "G"],
  ["H", "I", "J", "K", "L", "M", "N"],
]);

多列对象选择器

html
<vz-picker
  v-model="pickerValueMultiObj"
  :data="listDataMultiObj"
  :dataMap="{ value: 'id', label: 'name' }"
  placeholder="请选择"
  border
  radius="20rpx"
></vz-picker>
typescript
import { ref } from "vue";

const pickerValueMultiObj = ref([]);
const listDataMultiObj = ref([
  [
    { id: 1, name: "A" },
    { id: 2, name: "B" },
    { id: 3, name: "C" },
    { id: 4, name: "D" },
    { id: 5, name: "E" },
    { id: 6, name: "F" },
    { id: 7, name: "G" },
  ],
  [
    { id: 11, name: "H" },
    { id: 12, name: "I" },
    { id: 13, name: "J" },
    { id: 14, name: "K" },
    { id: 15, name: "L" },
    { id: 16, name: "M" },
    { id: 17, name: "N" },
  ],
]);

禁用状态

html
<vz-picker v-model="pickerValue" :data="listData" placeholder="请选择" border disabled radius="20rpx"></vz-picker>
typescript
import { ref } from "vue";

const pickerValue = ref("");
const listData = ref(["A", "B", "C", "D", "E", "F", "G"]);

只读状态

html
<vz-picker v-model="pickerValue" :data="listData" placeholder="请选择" border readonly radius="20rpx"></vz-picker>
typescript
import { ref } from "vue";

const pickerValue = ref("");
const listData = ref(["A", "B", "C", "D", "E", "F", "G"]);

可清除

html
<vz-picker v-model="pickerValue" :data="listData" placeholder="请选择" border clearable radius="20rpx"></vz-picker>
typescript
import { ref } from "vue";

const pickerValue = ref("");
const listData = ref(["A", "B", "C", "D", "E", "F", "G"]);

Props

属性名说明类型默认值
v-model / model-value绑定的值string / number / (string / number)[]-
data选择器数据Array[]
data-map数据 value & label 映射对象(注:微信小程序 dataMap)object-
placeholder未选择时占位符string-
disabled是否禁用booleanfalse
readonly是否只读booleanfalse
clearable是否可清空booleanfalse
border是否显示输入框边框booleanfalse
prefix-icon前置图标string-
suffix-icon后置图标string-
confirm-text确定按钮文案stringConfirmView.confirmText
cancel-text取消按钮文案stringConfirmView.cancelText
z-indexz-indexnumber \ stringPopup.zIndex
radius弹窗圆角string \ number0
overlay-closeable点击遮罩层是否关闭弹窗booleantrue
safe-area-inset-bottom是否开启底部安全区适配booleanPopup.safeAreaInsetBottom
mask-class选择器未选中项蒙层的类名stringvz-picker__mask
mask-style选择器未选中项蒙层的样式Vue.CSSProperties-
indicator-class选择器选中项的类名stringvz-picker__indicator
indicator-style选择器选中项的类名Vue.CSSProperties-
immediate-change触发 columnchange 事件时机。true: 手指松开时立即触发; false: 滚动动画结束后触发;booleanfalse
separatorlabel 显示分隔符string-
validate是否触发表单校验booleantrue
i-class根节点样式类string-
i-style根节点样式Vue.CSSProperties-

DataMap

属性名说明类型默认值
valuevalue 对应的 key 值string / numbervalue
labellabel 对应的 key 值string / numberlabel

Events

事件名说明参数
confirm点击确定按钮触发{ value: (number / string)[], label: (number / string)[], index: number[] }
cancel点击取消按钮触发-
columnchange列改变时触发{ column: number; index: number }
clear点击清空图标触发-

Slots

插槽名说明
default默认插槽

CSS

变量名说明默认值
--vz-picker-content-padding选择器内边距30rpx 20rpx 0
--vz-picker-view-height选择器滚动区高度620rpx
--vz-picker-radius选择器圆角-
--vz-picker-indicator-height选择器每项高度100rpx

SCSS

scss
$picker: (
  "view-height": 650rpx,
  "indicator-height": 100rpx,
  "mask-bg-color": getCssVar("bg-color", "rgb"),
);