vue實現(xiàn)日歷表格(element-ui)
本文實例為大家分享了vue實現(xiàn)日歷表格的具體代碼,供大家參考,具體內(nèi)容如下
效果如圖:
html:后面的日期是循環(huán)出來的
<div class="calendar-title"> <span class="calendar-left" @click="lastDateclick"><</span> <span class="calendar-center">近期事件</span> <span class="calendar-right" @click="nextDateclick">></span> </div> <el-table ref="table"t :data="filterData" border stripe> <el-table-column align="center" type="index" width="50" label="序號"></el-table-column> <el-table-column align="center" prop="code" label="代碼"> </el-table-column> <el-table-column align="center" prop="name" label="名稱"></el-table-column> <el-table-column align="center" v-for="(item,index) in dateArr" :key="index + item" :label="item"> <template slot-scope="scope"> <span v-html="dateInfoDesc(item,scope.row)"></span> </template> </el-table-column> </el-table>
這里注意一下:key="index + item" ,之前我的key設(shè)置的只等于index,然后到了后面數(shù)據(jù)刪選的時候就各種出錯,找了半天,才發(fā)現(xiàn)是key值不唯一導(dǎo)致的!!
data:
bondList: [], // 獲取到數(shù)據(jù)組 leftDate: "", rightDate: "", TempleftDate: "", TemprightDate: "", dateArr: []
js:
computed: { // 監(jiān)聽數(shù)據(jù)的日期滿足條件,則顯示該數(shù)據(jù) filterData() { var tableData = new Array(); var _this = this; this.dataList.filter(item => { if ( _this.dateArr.includes(item.startDate) || _this.dateArr.includes(item.endDate) || _this.dateArr.includes(item.refundDate) ) { tableData.push(item); } else { return; } }); return tableData; } }, methods: { // 顯示該數(shù)據(jù)在當(dāng)前日期對應(yīng)的描述內(nèi)容 dateInfoDesc(date, row) { var msg = ""; if (row.startDate == date) { msg = "起始日"; } else if (row.endDate == date) { msg = "結(jié)束日"; } else if (row.otherDate == date) { msg = "其他"; } return msg; }, // 獲取數(shù)據(jù) getDataList() { this.$axios.post(url).then(res => { this.dataList = res.data.data.rows; }); }, // 獲取日期數(shù)據(jù),返回的全是日期 getDateList() { var params = new URLSearchParams(); params.append("leftDate", this.leftDate); params.append("rightDate", this.rightDate); this.$axios({ method: "post", url: `url2`, params: params }).then(res => { this.dateArr = res.data.data; //日期數(shù)據(jù) this.TempleftDate = this.dateArr[0]; // 該區(qū)間日期第一位 this.TemprightDate = this.dateArr[this.dateArr.length - 1]; // 該區(qū)間日期最后一位 this.leftDate = []; this.rightDate = []; }); }, // 上一區(qū)間的日期 lastDateclick() { this.leftDate = this.TempleftDate; this.getDateList(); }, // 下一區(qū)間的日期 nextDateclick() { this.rightDate = this.TemprightDate; this.getDateList(); }, }
有問題留言哈,希望能帶給你幫助。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue中父組件通過props向子組件傳遞數(shù)據(jù)但子組件接收不到解決辦法
大家都知道可以使用props將父組件的數(shù)據(jù)傳給子組件,下面這篇文章主要給大家介紹了關(guān)于vue中父組件通過props向子組件傳遞數(shù)據(jù)但子組件接收不到的解決辦法,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-01-01vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解
這篇文章主要介紹了vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03Vue MVVM模型與data及methods屬性超詳細講解
MVVM旨在利用WPF中的數(shù)據(jù)綁定函數(shù),通過從視圖層中幾乎刪除所有GUI代碼(代碼隱藏),更好地促進視圖層開發(fā)與模式其余部分的分離,這篇文章主要介紹了Vue MVVM模型與data及methods屬性2022-10-10