From 13b0b42528666336dff43d142c1db94324f78d52 Mon Sep 17 00:00:00 2001 From: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:57:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(table):=20=E6=B7=BB=E5=8A=A0=20resizeObser?= =?UTF-8?q?ver=20(#1773)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(table): 添加 resizeObserver * fix(table): 避免重复创建 observe --- src/modules/table.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/table.js b/src/modules/table.js index 8f608e9c..0e958def 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -413,7 +413,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ that.renderStyle(); // 生成替代元素 - hasRender[0] && hasRender.remove(); // 如果已经渲染,则 Rerender + if(hasRender[0]){ + that.resizeObserver && that.resizeObserver.unobserve(that.elem[0]); + hasRender.remove(); // 如果已经渲染,则 Rerender + } othis.after(reElem); // 各级容器 @@ -2704,6 +2707,15 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ e.preventDefault(); that.layMain.scrollTop(scrollTop + (delta > 0 ? -step : step)); }); + + if(window.ResizeObserver){ + if(!that.resizeObserver){ + that.resizeObserver = new ResizeObserver(function(){ + table.resize(that.key); + }); + } + that.resizeObserver.observe(that.elem[0]); + } }; // 全局事件