網站首頁 編程語言 正文
因為el-table在折疊面板下面,所以設想當折疊面板折疊后,table可以根據高度自適應變高,使可視區域更大
因為折疊面板使用的是動畫,所以要監聽動畫結束,再獲取折疊后的高度,再更新表格的最大高度即可
<el-collapse
v-model="active"
accordion
@change="handleCollapseChange"
ref="myCollapseRef"
>
<el-collapse-item title="日歷圖" name="1">
<div style="width: 100%; display: flex">
<calendar-charts
:calendarMonthData="calendarMonthData"
:monthNum="time"
@getData="getCalendarClickData"
ref="calendarRef"
></calendar-charts>
</div>
</el-collapse-item>
</el-collapse>
?
<script>
export default {
data() {
return {
...
}
},
mounted() {
this.clientWidth = document.documentElement.clientWidth || document.body.clientWidth;
this.clientHeight = document.documentElement.clientHeight || document.body.cientHeight;
// 獲取折疊面板折疊前的高度
const preCollapseHeight = this.$refs.myCollapseRef.$el.offsetHeight;
this.otherHeight = Math.ceil($(".el-row").outerHeight()) + preCollapseHeight;
// this.maxHeight1 = this.clientHeight - this.otherHeight - 150 + "px";
window.onresize = () => {
this.clientHeight =
document.documentElement.clientHeight || document.body.clientHeight;
this.updateMaxHeight(this.clientHeight, this.otherHeight);
};
this.updateMaxHeight(this.clientHeight, this.otherHeight);
},
watch: {
clientHeight(val) {
this.updateMaxHeight(val, this.otherHeight);
},
otherHeight(val) {
this.updateMaxHeight(this.clientHeight, val);
}
},
methods: {
updateMaxHeight(clientHeight, otherHeight) {
if (!this.timer) {
this.clientHeight = clientHeight;
this.otherHeight = otherHeight;
this.timer = true;
let that = this;
setTimeout(function () {
that.maxHeight1 = that.clientHeight - that.otherHeight - 155 + "px";
//160是頂部和底部button加table上邊距的高度
that.timer = false;
}, 100);
}
},
// 監聽折疊狀態
handleCollapseChange() {
// 折疊前的高度
const preCollapseHeight = this.$refs.myCollapseRef.$el.offsetHeight;
this.otherHeight = Math.ceil($(".el-row").outerHeight()) + preCollapseHeight;
this.updateMaxHeight(this.clientHeight, this.otherHeight);
// 監聽過渡動畫結束事件
this.$refs.myCollapseRef.$el.addEventListener("transitionend", this.handleTransitionEnd);
},
handleTransitionEnd() {
// 折疊后的高度
const postCollapseHeight = this.$refs.myCollapseRef.$el.offsetHeight;
// 移除過渡動畫結束事件的監聽器
this.$refs.myCollapseRef.$el.removeEventListener("transitionend", this.handleTransitionEnd);
// 在這里可以對折疊前后的高度進行處理
this.otherHeight = Math.ceil($(".el-row").outerHeight()) + postCollapseHeight;
this.updateMaxHeight(this.clientHeight, this.otherHeight);
},
}
}
</script>
原文鏈接:https://blog.csdn.net/m0_62323730/article/details/131398439
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-01-10 微信小程序報錯 Cannot read property ‘forceUpdate‘ of u
- 2022-05-03 詳解Python實現圖像分割增強的兩種方法_python
- 2022-05-11 django配置DJANGO_SETTINGS_MODULE的實現_python
- 2022-04-18 C++中的命名空間詳細介紹_C 語言
- 2022-10-17 QT?TCP實現簡單的通信示例_C 語言
- 2023-05-17 一文速學Python+Pyecharts繪制樹形圖_python
- 2022-11-30 React中常見的TypeScript定義實戰教程_React
- 2022-08-11 golang時間及時間戳的獲取轉換_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支