This commit is contained in:
Pan 2019-03-15 15:59:24 +08:00
parent 4cce10d8af
commit d3a0798589
1 changed files with 22 additions and 14 deletions

View File

@ -7,27 +7,35 @@ import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/re
* el-table height is must be set * el-table height is must be set
* bottomOffset: 30(default) // The height of the table from the bottom of the page. * bottomOffset: 30(default) // The height of the table from the bottom of the page.
*/ */
const doResize = (el, binding, vnode) => {
const { componentInstance: $table } = vnode
const { value } = binding
if (!$table.height) {
throw new Error(`el-$table must set the height. Such as height='100px'`)
}
const bottomOffset = (value && value.bottomOffset) || 30
if (!$table) return
const height = window.innerHeight - el.getBoundingClientRect().top - bottomOffset
$table.layout.setHeight(height)
$table.doLayout()
}
export default { export default {
bind(el, binding, vnode) { bind(el, binding, vnode) {
const { componentInstance: $table } = vnode
const { value } = binding
if (!$table.height) {
throw new Error(`el-$table must set the height. Such as height='100px'`)
}
const bottomOffset = (value && value.bottomOffset) || 30
el.resizeListener = () => { el.resizeListener = () => {
if (!$table) return doResize(el, binding, vnode)
const height = window.innerHeight - el.getBoundingClientRect().top - bottomOffset
$table.layout.setHeight(height)
$table.doLayout()
} }
addResizeListener(el, el.resizeListener) addResizeListener(el, el.resizeListener)
}, },
inserted(el, binding, vnode) {
doResize(el, binding, vnode)
},
unbind(el) { unbind(el) {
removeResizeListener(el, el.resizeListener) removeResizeListener(el, el.resizeListener)
} }