element是vue功能比較全的後臺管理系統UI,可是已經不維護了,在一些細節上仍是有一點問題,項目中遇到一點問題,以下圖:vue
當出現橫向滾動條的時候,滾動條在下方,向右滑動的時候表頭就看不到了 markdown
能夠加一個 :show-overflow-tooltip="true",超寬之後就會顯示...,而後會加一個hover的tips
複製代碼
可是這個高度是固定的,遇到分辨率不同的屏幕就會效果不同this
由於高度是固定的,當遇到只有一條數據的會出現下面大量留白的狀況spa
tableHeight = 獲取視圖的高度 - 可滑動的高度 - 視圖內其餘的高度
複製代碼
tableHeight = .el-table__body的高度 + .el-table__header的高度
複製代碼
tableHeight = null
複製代碼
封裝一個方法放設置高度的function設計
/**
* @author Wujy
* @date 2020/11/10
* @Description: 設置table的固定滾筒條
*/
export function setHeight() {
const offsetTop = window.innerHeight - this.$refs.table.$el.offsetTop - 210
const offsetBodyHeight = document.querySelector('.el-table__body').offsetHeight
console.log(offsetTop, offsetBodyHeight)
if (this.tableList.length && offsetBodyHeight < offsetTop) {
this.tableHeight = offsetBodyHeight + 75
} else if (!this.tableList.length) {
this.tableHeight = null
} else {
this.tableHeight = offsetTop
}
}
複製代碼
頁面的業務代碼,在initTable來操做方便處理code
initTable() { // table列表查詢
getList(this.searchParams).then(res => {
if (res.data.list) {
this.$nextTick(() => {
setHeight.call(this)
})
this.tableList = res.data.list
}
}).catch(err => {
})
},
複製代碼
最後效果orm
除了這個表格的固定表頭功能,對比ant-desgin還有不少不人性化的設計,好比查詢列表上面的超寬隱藏,也須要本身來處理一下ip
能夠用element提供的Collapse來解決element
公衆號地址get