vue mint-ui學(xué)習(xí)筆記之picker的使用
本文介紹了vue mint-ui picker的使用,分享給大家,也給自己留個學(xué)習(xí)筆記
Picker的使用
import { Picker } from 'mint-ui'; Vue.component(Picker.name, Picker);
API
示例一:picker的簡單使用
xxx.vue:
<template> <div id="app"> <mt-picker :slots="slots" ></mt-picker> <router-view></router-view> </div> </template> <script> export default { data () { return { slots:[{values: ['年假', '事假', '病假', '婚假', '其他']}] } }, mounted:function(){ } } </script> <style> </style>
show:
picker顯示出來了
分析:
pincker的顯示,會在上方留下一半的白
當(dāng)拖動的時候,選項就會跑到上方預(yù)留的空白位置
示例二:picker的簡單使用——分組picker
xxx.vue:
<template> <div id="app"> <mt-picker :slots="slots" ></mt-picker> <router-view></router-view> </div> </template> <script> export default { data () { return { slots: [ { flex: 1, values: ['年假', '事假', '病假', '婚假', '其他'], className: 'slot1', textAlign: 'left' }, { divider: true, content: '-', className: 'slot2' }, { flex: 1, values: ['2015-11', '2015-02', '2015-03', '2015-04', '2015-05', '2015-06'], className: 'slot3', textAlign: 'right' } ] } }, mounted:function(){ } } </script> <style> </style>
show:
分析:
1.picker還可以拆分成左中右3個部分——具體可以看上面的slot對象的屬性
通過slots屬性的設(shè)置對應(yīng)的數(shù)據(jù),接收一個數(shù)組,數(shù)組里面分3個對象
對象內(nèi)除了可以使用values外,還可以使用flex(彈性盒子的flex值,1是充滿剩余空間),className(使用slot1、slot2、slot3),textAlign(設(shè)置文字的水平位置,可以使用left、center、right)
2.每個picker的高度默認(rèn)是36px
示例三:picker使用change事件
xxx.vue:
<template> <div id="app"> <mt-picker :slots="slots" @change="onValuesChange" ></mt-picker> <router-view></router-view> </div> </template> <script> export default { name: 'app', data () { return { slots: [ { flex: 1, values: ['年假', '事假', '病假', '婚假', '其他'], className: 'slot1', textAlign: 'left' }, { divider: true, content: '-', className: 'slot2' }, { flex: 1, values: ['2015-11', '2015-02', '2015-03', '2015-04', '2015-05', '2015-06'], className: 'slot3', textAlign: 'right' } ] } }, mounted:function(){ }, methods: { onValuesChange(picker, values) { console.log(picker) console.log(values) } } } </script> <style> </style>
show:
運行后,change事件會自動輸出2次內(nèi)容
這是因為,這里面有2個picker可以選擇內(nèi)容
分析:
當(dāng)滾動其中一列的時候,又會觸發(fā)change事件
示例四:獲取change事件所選的內(nèi)容
xxx.vue:
<template> <div id="app"> <mt-picker :slots="slots" @change="onValuesChange" ></mt-picker> <router-view></router-view> </div> </template> <script> export default { name: 'app', data () { return { value:'', slots: [ { values: ['年假', '事假', '病假', '婚假', '其他', '婚假'] } ] } }, mounted:function(){ }, methods: { onValuesChange(picker, values) { this.value = values[0]; console.log(this.value) } } } </script> <style> </style>
show:
開啟picker的時候,在沒有操作的時候,會先自動執(zhí)行一次change事件,選中第一個選項的內(nèi)容
更改選擇的內(nèi)容,輸出了data內(nèi)的數(shù)據(jù)
示例五:picker的顯示個數(shù)
xxx.vue:
<template> <div id="app"> <mt-picker :slots="slots" @change="onValuesChange" :visible-item-count="1"></mt-picker> <router-view></router-view> </div> </template> <script> export default { name: 'app', data () { return { value:'', slots: [ { values: ['年假', '事假', '病假', '婚假', '其他', '婚假'] } ], } }, mounted:function(){ }, methods: { onValuesChange(picker, values) { this.value = values[0]; console.log(this.value) } } } </script> <style> </style>
show:
使用了:visible-item-count="1"之后,picker的可顯示個數(shù)就變成了1個
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue.js中mint-ui框架的使用方法
- 詳解Vue2.0配置mint-ui踩過的那些坑
- vue基于mint-ui實現(xiàn)城市選擇三級聯(lián)動
- vue.js整合mint-ui里的輪播圖實例代碼
- Vue.js 的移動端組件庫mint-ui實現(xiàn)無限滾動加載更多的方法
- 解決Vue使用mint-ui loadmore實現(xiàn)上拉加載與下拉刷新出現(xiàn)一個頁面使用多個上拉加載后沖突問題
- vue使用mint-ui實現(xiàn)下拉刷新和無限滾動的示例代碼
- vue基于mint-ui的城市選擇3級聯(lián)動的示例
- vue mint-ui 實現(xiàn)省市區(qū)街道4級聯(lián)動示例(仿淘寶京東收貨地址4級聯(lián)動)
- vue前端框架—Mint UI詳解(更適用于移動端)
相關(guān)文章
淺析vue 函數(shù)配置項watch及函數(shù) $watch 源碼分享
這篇文章主要介紹了vue 函數(shù)配置項watch及函數(shù) $watch 源碼分享 ,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-11-11vue添加錨點,實現(xiàn)滾動頁面時錨點添加相應(yīng)的class操作
這篇文章主要介紹了vue添加錨點,實現(xiàn)滾動頁面時錨點添加相應(yīng)的class操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08Vue2 Element Schema Form 配置式生成表單的實現(xiàn)
本文主要介紹了Vue2 Element Schema Form 配置式生成表單的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05