Vue2 cube-ui時間選擇器詳解
前言
vue2 整合 cube-ui 時間選擇器(供有點點基礎(chǔ)的看)
一、需求及效果
需求
我們要在原搜索的情況下,加搜索時間
效果
二、代碼實現(xiàn)
index.vue(html)
<div class="header"> <cube-input v-on:focus="showMinPicker('startTime')" v-model="startTime" placeholder="開始時間" :maxlength=30 style="width: 50%;"></cube-input> <span>到</span> <cube-input v-on:focus="showMinPicker('endTime')" v-model="endTime" placeholder="結(jié)束時間" :maxlength=30 style="width: 50%;"></cube-input> </div>
解析:
- cube-input cube自帶的輸入框。
- v-on:focus=“showMinPicker(‘startTime')” v-on監(jiān)聽事件,focus指的是輸入框聚焦后觸發(fā)此事件,如果禁用狀態(tài),則不觸發(fā)。
- v-model 雙向綁定(用于時間顯示)
- maxlength 最大長度
date
data () { return { // 開始時間 startTime: '', // 結(jié)束時間 endTime: '', // 時間標識 timeIdentifying: '' } }
methods
methods: { // 監(jiān)聽出發(fā)選擇時間 showMinPicker (time) { if (!this.minPicker) { this.minPicker = this.$createDatePicker({ title: '選擇時間', visible: true, // 最小時間 min: new Date(2000, 0, 1), // 最大時間 max: new Date(2099, 12, 1), // 當(dāng)前時間 value: new Date(), // 顯示的格式 format: { year: 'YYYY', month: 'MM', date: 'DD' }, // 顯示多少列 columnCount: 3, // 選擇時間確定后 onSelect: this.selectHandler, // 選擇時間取消后 onCancel: this.cancelHandler }) } // 選擇時間標識 this.timeIdentifying = time // 顯示 this.minPicker.show() }, // 選擇時間確定后 三個參數(shù)是不同的時間格式,可能根據(jù)自己需求定 selectHandler (selectedTime, selectedText, formatedTime) { let time = '' for (let index = 0; index < selectedText.length; index++) { if (index === (selectedText.length - 1)) { time += selectedText[index] } else { time += selectedText[index] + '-' } } console.log('開始修改') if (this.timeIdentifying === 'startTime') { console.log('修改startTime') this.startTime = time } else if (this.timeIdentifying === 'endTime') { console.log('修改endTime') this.endTime = time } console.log('結(jié)束修改') }, // 取消事件 cancelHandler () { // 清空選擇好的時間 this.startTime = '' this.endTime = '' } }
測試效果
三、資料參考
input
TimePicker(時間選擇器)
詳細在官網(wǎng)地址:
官網(wǎng)地址:https://didi.github.io/cube-ui/#/zh-CN
Cube-ui中文文檔地址:https://www.bookstack.cn/read/Cube-UI-zh/30.md
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
深入淺出 Vue 系列 -- 數(shù)據(jù)劫持實現(xiàn)原理
深入淺出 Vue 系列 -- 數(shù)據(jù)劫持實現(xiàn)原理2019-04-04Vue 微信端掃描二維碼蘋果端卻只能保存圖片問題(解決方法)
這幾天在做項目時遇到微信掃描二維碼的然后進入公眾號網(wǎng)頁巴拉巴拉的,然后就很順利的遇到了在安卓端掃碼的時候,順利的一塌糊涂,然后到了蘋果端的時候,就只能出現(xiàn)一個保存圖片,然后就寫一下記錄一下這問題的解決方法2020-01-01vue中動態(tài)出來返回的時間秒數(shù)(在多少秒顯示分、小時等等)
這篇文章主要給大家介紹了關(guān)于vue中動態(tài)出來返回的時間秒數(shù)(在多少秒顯示分、小時等等)的相關(guān)資料,文中通過代碼示例介紹的非常詳細,對大家學(xué)習(xí)或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01