- // 处理调整大小
- function handleResize(collapsed) {
- if (spreadSheet.value) {
- const newWidth = collapsed
- ? `${window.innerWidth - 200}px`
- : `${window.innerWidth - 400}px`;
- const host = spreadSheet.value.getHost();
- if (host.style.width !== newWidth) {
- host.style.width = newWidth;
- window.dispatchEvent(new Event('resize')); // 触发 resize 事件
- }
- }
- }
- // 防抖函数实现
- function debounce(func, wait) {
- let timeout;
- return function (...args) {
- clearTimeout(timeout);
- timeout = setTimeout(() => func(...args), wait);
- };
- }
- // 使用防抖技术优化 watch 函数
- const debouncedHandleResize = debounce(handleResize, 100);
- watch(
- () => appStore.layoutSetting.collapsed,
- (collapsed) => {
- debouncedHandleResize(collapsed);
- },
- );
复制代码 用了防抖好多了,还是不丝滑 |