這篇文章給大家介紹怎么解析Vue2 cube-ui時間選擇器,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
vue2 整合 cube-ui 時間選擇器(供有點點基礎的看)
我們要在原搜索的情況下,加搜索時間
<div class="header"> <cube-input v-on:focus="showMinPicker('startTime')" v-model="startTime" placeholder="開始時間" :maxlength=30 ></cube-input> <span>到</span> <cube-input v-on:focus="showMinPicker('endTime')" v-model="endTime" placeholder="結束時間" :maxlength=30 ></cube-input> </div>
解析:
cube-input cube自帶的輸入框。
v-on:focus=“showMinPicker(‘startTime')” v-on監聽事件,focus指的是輸入框聚焦后觸發此事件,如果禁用狀態,則不觸發。
v-model 雙向綁定(用于時間顯示)
maxlength 最大長度
data () { return { // 開始時間 startTime: '', // 結束時間 endTime: '', // 時間標識 timeIdentifying: '' } }
methods: { // 監聽出發選擇時間 showMinPicker (time) { if (!this.minPicker) { this.minPicker = this.$createDatePicker({ title: '選擇時間', visible: true, // 最小時間 min: new Date(2000, 0, 1), // 最大時間 max: new Date(2099, 12, 1), // 當前時間 value: new Date(), // 顯示的格式 format: { year: 'YYYY', month: 'MM', date: 'DD' }, // 顯示多少列 columnCount: 3, // 選擇時間確定后 onSelect: this.selectHandler, // 選擇時間取消后 onCancel: this.cancelHandler }) } // 選擇時間標識 this.timeIdentifying = time // 顯示 this.minPicker.show() }, // 選擇時間確定后 三個參數是不同的時間格式,可能根據自己需求定 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('結束修改') }, // 取消事件 cancelHandler () { // 清空選擇好的時間 this.startTime = '' this.endTime = '' } }
關于怎么解析Vue2 cube-ui時間選擇器就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。