Skip to content

Commit

Permalink
enhance: tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Dec 9, 2024
1 parent 7b2365b commit b2b7ebc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions front/terminal/src/components/ToolTip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,28 @@ export default {
},1);
};
// 使用MutationObserver监听DOM变化
let mutationObserver = null;
// 使用ResizeObserver监听尺寸变化
let resizeObserver = null;
const observeTextChanges = () => {
const observeSizeChanges = () => {
if(tooltipContent.value) {
mutationObserver = new MutationObserver(() => {
resizeObserver = new ResizeObserver(() => {
checkOverflow();
});
mutationObserver.observe(tooltipContent.value, {
childList: true, // 监听子节点的变化
subtree: true, // 监听所有后代节点的变化
characterData: true, // 监听文本节点的变化
});
resizeObserver.observe(tooltipContent.value);
}
};
onMounted(() => {
checkOverflow();
observeTextChanges();
observeSizeChanges();
});
onBeforeUnmount(() => {
if(mutationObserver) mutationObserver.disconnect();
if(resizeObserver && tooltipContent.value) {
resizeObserver.unobserve(tooltipContent.value);
resizeObserver.disconnect();
}
});
return {
Expand Down

0 comments on commit b2b7ebc

Please sign in to comment.