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

[Bug Report] tabs组件报错Cannot read properties of null (reading \'width\') #5210

Open
pointline opened this issue Feb 2, 2023 · 2 comments

Comments

@pointline
Copy link

重现链接

Vant Weapp 版本

1.10.12

描述一下你遇到的问题。

感谢vant-weapp团队提供组件

我的问题:
使用tabs组件,但是tab是通过数据请求,然后数据遍历渲染出来的。小程序统计JS报错Cannot read properties of null (reading \'width\')
查看组件源码发现,猜测可能是tabs组件中在mountd使用requestAnimationFrame执行任务,是否可以将requestAnimationFrame替换为nextTick 。因为渲染tags有可能内部tab还没有遍历渲染完,就不能获取到内部的tab元素

小程序报错截图
image

小程序编译代码断点截图
image

源代码tabs组件截图
image
image

感谢帮助

重现步骤

  1. 一个固定静态tab
  2. 其他tab通过数据遍历

设备/浏览器

Android

@johnsonwong666
Copy link
Collaborator

我尝试了一下setTimeout去异步获取数据并设置data 但是没有看到控制台有错误信息 可以提供一个小程序代码片段吗?

@lionztt
Copy link

lionztt commented May 28, 2024

该问题有个类似的问题,当页面切换过快,tabs元素来不及渲染,此时获取也是null,会导致line位置错误和js报错:Cannot read property 'width' of null,这里能否更改获取元素时机呢

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

No branches or pull requests

3 participants