Element Ul(Vue)表格高度根据窗口大小自适应
2020-06-01 本文已影响0人
Zxy_i
浏览器F11全屏效果
全屏.jpg浏览器窗口缩小效果
小屏.jpg1.结合Vuex 来保存状态,路由跳转到别的表格时,保证当前高度是自适应后的高度
export default {
state: {
getHeigth:0 ,//表格高度
},
getters: {
},
mutations: {
setHeigth(state, num){
console.log( ((num.split('px')[0]) - 100 ))
state.getHeigth = ((num.split('px')[0]) - 240 );
}
},
actions: {
}
}
2.在Element 的 el-table 组件上绑定 height
<template>
<div ref = "getHeight">
<el-table ref="multipleTable" :data="tableData" :height="getHeigth" >
<el-table-column type="selection" ></el-table-column>
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
}
},
computed: {
getHeigth () {
return this.$store.state.app.getHeigth
}
},
mounted(){
const that = this
this.$store.commit("setHeigth", window.getComputedStyle(that.$refs.getHeight).height);
window.onresize = () => {
this.$store.commit("setHeigth", window.getComputedStyle(that.$refs.getHeight).height);
}
},
},
}
</script>