Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置parent后,父级窗口大小改变,限制的位置没有重新计算 #106

Open
zhangzhenfei opened this issue Mar 1, 2024 · 2 comments

Comments

@zhangzhenfei
Copy link

设置parent后,父级窗口大小改变,限制的位置没有重新计算

@linfeng023
Copy link

设置parent后,父级窗口大小改变,限制的位置没有重新计算

有想到解决的方法吗?

@wcn007
Copy link

wcn007 commented Jun 18, 2024

自己打了个补丁,供参考

export function initParent(containerRef: Ref<HTMLElement | undefined>) {
  const parentWidth = ref(0)
  const parentHeight = ref(0)
  const upParent = ()=>{
    if (containerRef.value && containerRef.value.parentElement) {
      const { width, height } = getElSize(containerRef.value.parentElement)      
      parentHeight.value = height
      parentWidth.value = width
    }
  }  
  onMounted(() => {
    upParent();
    const observer = new ResizeObserver(upParent);
    observer.observe(containerRef.value!.parentElement as any)
  })


  return {
    parentWidth,
    parentHeight
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants