自适应表格
路径:/src/components/AcTable/AdaptiveTable.vue
说明:使用VUE的指令功能,计算表格距离屏幕底部的距离,并更新自身的高度。
Attributes
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
adaptive | 是否启用高度自适应 | String | true、false | true |
bottomOffset | 表格底部距离屏幕底部的距离 | Number | - | 30 |
自定义指令
路径:/src/directive/eltable
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 {
bind(el, binding, vnode) {
el.resizeListener = () => {
Vue.prototype.$nextTick(() => {
doResize(el, binding, vnode)
})
}
window.addEventListener('resize', el.resizeListener)
},
inserted(el, binding, vnode) {
Vue.prototype.$nextTick(() => {
doResize(el, binding, vnode)
})
},
update(el, binding, vnode) {
Vue.prototype.$nextTick(() => {
doResize(el, binding, vnode)
})
},
unbind(el) {
window.removeEventListener('resize', el.resizeListener)
}
}