使用了vue生命周期中的activated函数,响应窗口变化,在keep-alive中返回页面依旧有用。
代码如下:
<template>
<el-table :max-height="maxheight">
</el-table>
</template>
<script>
export default {
data() {
return {
//表格最大高度
maxheight: window.innerHeight - 270,
};
},
activated() {
//表格高度自适应窗口
this.maxheight = window.innerHeight - 270;
window.onresize = () => {
return (() => {
this.maxheight = window.innerHeight - 270;
})()
}
}
};
</script>