1.0.0 • Published 6 years ago

vue-check-picker v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

vue-awesome-picker NPM Version NPM Downloads

基于 Vue.js & Better-Scroll 的移动端 picker 组件

Features

  • 支持单列、多列和联级数据
  • 内置时间、日期数据
  • 滚轮 3D 效果
  • 颜色可配置

Demo

PS:Demo 已启用 Service Worker

npm.io

Installation

npm install vue-awesome-picker --save

Usage

/* main.js */
import AwesomePicker from 'vue-awesome-picker';
Vue.use(AwesomePicker);
/* 详细使用方法参照源码 App.vue */
<awesome-picker
  ref="picker"
  :data="picker.data"
  :anchor="picker.anchor"
  :textTitle="picker.textTitle"
  :textConfirm="picker.textConfirm"
  :textCancel="picker.textCancel"
  :colorTitle="picker.colorTitle"
  :colorConfirm="picker.colorConfirm"
  :colorCancel="picker.colorCancel"
  :swipeTime="picker.swipeTime"
  @cancel="handlePickerCancel"
  @confirm="handlePickerConfirm">
</awesome-picker>
methods: {
  show() {
    this.$refs.picker.show();
  }
}

Props

参数描述可选类型默认
data详细描述见下文Array
anchor详细描述见下文Array
type内置 picker 类型无需传入 datadate, timeString
textTitletitle 文案String
textConfirmconfirm 文案String确定
textCancelcancel 文案String取消
colorTitletitle 颜色String#000000
colorConfirmconfirm 颜色String#42b983
colorCancelcancel 颜色String#999999
swipeTime滚动速度(better-scroll swipeTime)Number1800

data

vue-awesome-picker 通过数据结构不同来区分是普通 picker 还是联级 picker, 所以请严格按照以下数据结构进行配置

单列、多列 picker 以双层数组的形式传入 data

[
  ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's','t', 'u', 'v', 'w', 'x', 'y', 'z'],
  ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S','T', 'U', 'V', 'W', 'X', 'Y', 'Z']
]

联级 picker 通过 children 构造出具有层级关系的数据

[
  {
    value: 'A',
    children: [
      { value: 'A-a' },
      { value: 'A-b' },
      { value: 'A-c' }
    ]
  },
  {
    value: 'B',
    children: [
      { value: 'B-a' },
      { value: 'B-b' }
    ]
  },
]

anchor

anchor 是 picker 展开时每一列默认滚动的锚点位置或值的数组, 兼容两种数据结构, 未匹配到默认选中第0项

推荐数组对象形式: 与事件 confirm 返回的参数数据结构相同, 对象里可以只存在 index 或 value, 当存在 index 时优先匹配 index

[
  { 
    index: 0,
    value: 'A'
  },
  {
    index: 0,
    value: 'A-a'
  } 
]

单层数组形式: index 组成的数组

[0, 0]

Methods

方法描述
show展开显示 picker

Events

事件描述参数
confirm点击 confirm 按钮后触发{ index: xxx, value: xxx }... index: 当前选中的 item 在当列的 index value: 当前选中 item 的 value
cancel点击 cancel 按钮后触发

Development

git clone git@github.com:Fyerl/vue-awesome-picker.git
cd vue-awesome-picker
npm install
npm run dev

Contact

npm.io