# picker-view

嵌入页面的滚动选择器。

基于该组件,组件库实现了底部弹起的滚动选择器 bz-picker 供开箱使用。

但当需要对自定义选择的弹出方式和 UI 表现时,往往需要使用 picker-view

# 使用示例


扫码预览
用BoosHi扫码或PC端点击
<template>
  <view class="demo-ui-page">
    <view class="demo-title">picker-view 滚动选择器</view>
    <demo-cell :title="`日期:${year}年${month}月${day}日`" noPadding>
      <picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view">
          <picker-view-column>
              <view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
          </picker-view-column>
          <picker-view-column>
              <view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
          </picker-view-column>
          <picker-view-column>
              <view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
          </picker-view-column>
      </picker-view>
    </demo-cell>
  </view>
</template>

<script>
	export default {
		data: function () {
      const date = new Date()
      const years = []
      const year = date.getFullYear()
      const months = []
      const month = date.getMonth() + 1
      const days = []
      const day = date.getDate()
      for (let i = 1990; i <= date.getFullYear(); i++) {
          years.push(i)
      }
      for (let i = 1; i <= 12; i++) {
          months.push(i)
      }
      for (let i = 1; i <= 31; i++) {
          days.push(i)
      }
      return {
        title: 'picker-view',
        years,
        year,
        months,
        month,
        days,
        day,
        value: [9999, month - 1, day - 1],
        visible: true,
        indicatorStyle: `height: 50px;`
      }
    },
    methods: {
      bindChange (e){
        const val = e.detail.value
        this.year = this.years[val[0]]
        this.month = this.months[val[1]]
        this.day = this.days[val[2]]
      }
    }
  }
</script>

<style lang="scss" scoped>
	.picker-view {
		width: 750rpx;
		height: 600rpx;
		margin-top: 20rpx;
        border-top: 1px solid #eee;
        border-bottom: 1px solid #eee;
        font-size: 14px;
	}
	.item {
		height: 50px;
        line-height: 50px;
		align-items: center;
		justify-content: center;
		text-align: center;
	}
</style>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
展开 刷新 关闭

# 属性说明

属性名 类型 默认值
value Array<Number> 数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
indicator-style String 设置选择器中间选中框的样式
indicator-class String 设置选择器中间选中框的类名,注意页面或组件的style中写了scoped时,需要在类名前写/deep/
mask-style String 设置蒙层的样式
mask-class String 设置蒙层的类名
@change EventHandle 当滚动选择,value 改变时触发 change 事件,event.detail = {value: value};value为数组,表示 picker-view 内的 picker-view-column 当前选择的是第几项(下标从 0 开始)

**注意:**其中只可放置 <picker-view-column/> 组件,其他节点不会显示。

# picker-view-column

<picker-view /> 的子组件,仅可放置于 <picker-view /> 中,其子节点的高度会自动设置成与 picker-view 的选中框的高度一致。

**注意:**nvue页面子节点未继承 picker-view 的选中框的高度,需要自己设置高度并居中。

最后更新于 : 6/14/2023, 9:28:52 PM