重寫微信小程序原生picker組件


weChat-picker

微信小程序下彈選擇器

 

為什么寫這個

官方的的太丑了

 

組件的引入方式

官方文檔

 

GitHub地址

https://github.com/loo41/weChat-picker

 

效果

image

 

引入

  將/pages/component/picker按組件引入既可以

使用

  <picker
    bind:sure="_sure" 
    bind:close="_close" 
    pickData="{{listData}}" 
    open="{{openPicker}}"
    sureStyle=""
    cancelStyle=""
  />
  data: {
    openPicker: false, listData: { years: ['2018年', '2017年', '2016年', '2015年'], months: ['12月', '11月', '10月', '9月', '8月', '7月', '6月'], days: ['1天', '2天', '3天', '4天', '5天', '6天', '7天', '8天'] }, } _sure (e) { let data = e.detail console.log(e.detail) if (JSON.stringify(e.detail) === '[]') { this.setData({openPicker: false}) return } let {value} = this.data value = data.join('') this.setData({ openPicker: false, value }) console.log('點擊了確定') }, _close (e) { console.log(e.detail) this.setData({openPicker: false}) console.log('點擊了取消') }, _openPick () { this.setData({openPicker: true}) }

使用

Props

名稱 類型 是否必須 說明
sure Function 點擊確定返回的事件
close Function 點擊取消返回的事件
pickData Object 數據對象, 參考使用
open Boolean 控制開啟或關閉picker
sureStyle-cancelStyle String 按鈕樣式

其他

1: pickData對象可以任意定制,只要和是對象-數組既可
2: open參數記得每次回調完,一定設置為false,不然下次就打不開
3: 如果看着不順眼,那就直接到組件里去去改樣式吧


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM