0.1.3 • Published 4 years ago

vue2-wheel-picker v0.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Vue2 Wheel Picker

A vue2.x based development, similar to the ios wheel style selection mobile plug-in, currently support time selection, single choice, multiple choice

Installation

  • by npm
$ npm install vue2-wheel-picker
  • by yarn
$ yarn add vue2-wheel-picker

Online Demo

Web Site Visit: https://lenvonsam.github.io/vue2-wheel-picker/

Mobile Visit:

mobile_demo

Screenshots:

shots_datepicker shots_picker

Usage

Global Config

import Vue from 'vue'
import wheelpicker from 'vue2-wheel-picker'

Vue.use(wheelpicker)

This plug-in automatically injects $wheelPicker Object and registers global components, including wheelPicker and wheelDatepicker.

Component Config

import { WheelPicker, WheelDatepicker } from 'vue2-wheel-picker/picker' 
export default {
  ...
  components: {
    'wheel-picker': WheelPicker,
    'wheel-datepicker': WheelDatepicker
  }
  ...
}

WheelPicker Properties

<wheel-picker v-model="pickerShow" :listData="list" :listValue="value" :colLen="2" @change="pickChange" :rowKeys="rowKeys"></wheel-picker>
PropertyRequiredTypeDefaultDescription
valuefalseBooleanfalseto display and close the component
listDatatrueArrayto display component's content
listValuefalseArrayto initail the component value and get the selected component value
colLenfalseNumber1The number of columns displayed by the component
rowKeysfalseArraySpecifies each column object keys
confirmTextfalseString确定confirm button text
cancelTextfalseString取消cancel button text
confirmColorfalseString#3db0fcconfirm button color(rgb,rgba,hex)
cancelColorfalseString#888cancel button color(rgb, rgba, hex)
bottomColorfalseString#dddthe color of button group bottom line

WheelDatepicker Properties

<wheel-datepicker v-model="datePickerShow" :listValue="dataVal" @change="dateChange"></wheel-datepicker>
PropertyRequiredTypeDefaultDescription
valuefalseBooleanfalseto display and close the component
dateValuefalseStringYYYY-MM-DDto initail the component value and get the selected component value, the value format depend on separator
separatorfalseString-Date separator
yearCountfalseNumber15The difference between the current year and the beginning year
confirmTextfalseString确定confirm button text
cancelTextfalseString取消cancel button text
confirmColorfalseString#3db0fcconfirm button color(rgb,rgba,hex)
cancelColorfalseString#888cancel button color(rgb, rgba, hex)
bottomColorfalseString#dddthe color of button group bottom line

Components Methods

MethodparamsRequiredDescrpiton
changevaluefalsereturn selected value

API Properties

It can also $wheelPicker Object to display wheelPicker and wheelDatepicker.

this.$wheelPicker.show({
  mode: 'date',
  cb (type) {
    console.log('type', type)
  }
})

Common Properties

PropertiesRequiredTypeDefaultDescription
modefalseStringpickerdisplay different mode wheel picker
confirmTextfalseString确定confirm button text
cancelTextfalseString取消cancel button text
confirmColorfalseString#3db0fcconfirm button color(rgb,rgba,hex)
cancelColorfalseString#888cancel button color(rgb, rgba, hex)
bottomColorfalseString#dddthe color of button group bottom line

Date Mode Properties

PropertiesRequiredTypeDefaultDescription
dateValuefalseStringYYYY-MM-DDto initail the component value and get the selected component value, the value format depend on separator
separatorfalseString-Date separator
yearCountfalseNumber15The difference between the current year and the beginning year

Picker Mode Properties

PropertiesRequiredTypeDefaultDescription
listDatatrueArrayto display component's content
listValuefalseArrayto initail the component value and get the selected component value
colLenfalseNumber1The number of columns displayed by the component
rowKeysfalseArraySpecifies each column object keys

Api Methods

MethodparamsRequiredDescrpiton
cbvaluefalsereturn selected value

Examples

Single String Picker

export default {
  data () {
    return {
      listData: ['orange', 'apple', 'banana'],
      listValue: ['apple']
    }
  },
  mounted () {
    this.$wheelPicker.show({
      listData: this.listData,
      listValue: this.listValue,
      cb (value) {
        console.log('picker value:>>', value)
      }
    })
  }
}

Multi Object columns Picker

export default {
  data () {
    return {
      listData: [[{'fruit': 'orange'}, {'fruit': 'banana'}], [{'animal': 'dog'}, {'animal': 'cat'}]],
      listValue: ['orange', 'cat']
    }
  },
  mounted () {
    this.$wheelPicker.show({
      listData: this.listData,
      listValue: this.listValue,
      colLen: this.listData.length,
      // when row type is object, rowkeys must not be null
      rowkeys: ['fruit', 'animal'],
      confirmColor: 'red',
      cb (value) {
        console.log('picker value:>>', value)
      }
    })
  }
}

Date Picker

export default {
  mounted () {
    // when dateValue not set value, the date wheel picker will set current date automatically
    this.$wheelPicker.show({
      mode: 'date',
      cb (value) {
        console.log('picker value:>>', value)
      }
    })
  }
}

Using Picker by Component

<template>
<div>
  <button @click="clickMe">点我选择</button>
  <picker v-model="pickerShow" :listData="list" :listValue="value" @change="pickerChange" :rowKeys="rowKeys"></picker>
</div>
</template>
import { WheelPicker } from 'vue2-wheel-picker/picker'
export default {
  data () {
    return {
      listData: ['1', '2', '3', '4', '5', '6'],
      listValue: ['1'],
      pickerShow: false
    }
  },
  components: {
    wheelPicker: WheelPicker
  },
  methods: {
    clickMe () {
      this.pickerShow = true
    },
    pickerChange (val) {
      console.log('choose value', val)
    }
  }
}

TO DO LIST

  • China City Picker
  • Theme Picker(ios, android...)

License

MIT License