在goods-list.vue页面销毁时移除 resize 事件监听器

Signed-off-by: luoyangxin <835168276@qq.com>
This commit is contained in:
luoyangxin 2025-04-14 02:23:17 +00:00 committed by Gitee
parent 51caeb1ad1
commit 7bad13fc23
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -498,29 +498,37 @@
//
const yHeight = ref(0);
onMounted(() => {
resetGetHeight();
});
function resetGetHeight() {
//
let doc = document.querySelector('.ant-form');
//
let btn = document.querySelector('.smart-table-btn-block');
//
let tableCell = document.querySelector('.ant-table-cell');
//
let page = document.querySelector('.smart-query-table-page');
//
let box = document.querySelector('.admin-content');
setTimeout(() => {
//
let doc = document.querySelector('.ant-form');
//
let btn = document.querySelector('.smart-table-btn-block');
//
let tableCell = document.querySelector('.ant-table-cell');
//
let page = document.querySelector('.smart-query-table-page');
//
let box = document.querySelector('.admin-content');
setTimeout(() => {
let dueHeight = doc.offsetHeight + 10 + 24 + btn.offsetHeight + 15 + tableCell.offsetHeight + page.offsetHeight + 20;
yHeight.value = box.offsetHeight - dueHeight;
}, 100);
}
window.addEventListener(
'resize',
_.throttle(() => {
resetGetHeight();
}, 1000)
);
//
let throttledResizeHandler;
onMounted(() => {
resetGetHeight();
throttledResizeHandler = _.throttle(() => {
resetGetHeight();
}, 1000);
window.addEventListener('resize', throttledResizeHandler);
});
// resize
onUnmounted(() => {
window.removeEventListener('resize', throttledResizeHandler);
});
</script>