1.表格设置:height="tableHeight"
2.data配置
data: function () {
return {
tableHeight: 0, // 表格高度
tableData: []
};
},
3.mounted中代码
mounted() {
this.$nextTick(function () {
// 表格高度自适应
const rect = this.$refs.tableContainer.$el.getBoundingClientRect();
this.tableHeight = rect.height
// 监听窗口大小变化
let _this = this;
window.onresize = function() {
// 表格高度自适应
const rect = _this.$refs.tableContainer.$el.getBoundingClientRect();
_this.tableHeight = rect.height
}
})
}