methods: {
getTableHeight() {
const AppMain = document.querySelector('.AppMain')
const searchForm = document.querySelector('.searchForm')
const tableTopBtns = document.querySelector('.ele-table-button-group')
const tablePagination = document.querySelector('.ele-table-pagination')
const AppMainHeight = (AppMain && AppMain.offsetHeight) || 0
const searchFormHeight = (searchForm && searchForm.offsetHeight) || 0
const tableTopBtnsHeight = (tableTopBtns && tableTopBtns.offsetHeight) || 0
const tablePaginationHeight = (tablePagination && tablePagination.offsetHeight) || 0
return AppMainHeight - searchFormHeight - tableTopBtnsHeight - tablePaginationHeight
},
setTableHeight() {
this.$nextTick(() => {
this.tableMaxHeight = this.getTableHeight()
})
}
}
优化
export const EleTableMixin = {
data() {
return {
tableData: [],
tableMaxHeight: 400,
total: 0
}
},
computed: {
options() {
return {
data: this.tableData,
maxHeight: this.tableMaxHeight
}
}
},
mounted() {
window.addEventListener('resize', () => {
this.setTableHeight()
})
},
methods: {
getTableHeight() {
const AppMain = document.querySelector('.AppMain')
const searchForm = document.querySelector('.searchForm')
const tableTopBtns = document.querySelector('.ele-table-button-group')
const tablePagination = document.querySelector('.ele-table-pagination')
const AppMainHeight = (AppMain && AppMain.offsetHeight) || 0
const searchFormHeight = (searchForm && searchForm.offsetHeight) || 0
const tableTopBtnsHeight = (tableTopBtns && tableTopBtns.offsetHeight) || 0
const tablePaginationHeight = (tablePagination && tablePagination.offsetHeight) || 0
return AppMainHeight - searchFormHeight - tableTopBtnsHeight - tablePaginationHeight
},
setTableHeight() {
this.$nextTick(() => {
this.tableMaxHeight = this.getTableHeight()
})
},
indexMethod(index) {
return (this.searchForm.page - 1) * this.searchForm.rows + index + 1
}
}
}