-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Taro.pxTransform report error: Cannot read property '750' of undefined #14360
Comments
fixed in #14352 |
@ZakaryCode 有点不理解,为什么taro.config是空的? |
@ZakaryCode 还是会有问题的。
因为config是空的,导致这里targetUnit是undefined,所以这里的result是NaN. 所以这个问题的根源应该是,为什么taro.config没有数据? |
修改后为空应当会使用默认的 ratio 配置才对,可以看看 initPxTransform 执行是否正确 |
导出的自定义组件? |
可以看看我那个demo。我只是写了一个函数用到了。然后它实际上是在一个theme里面定义变量值用的。这个theme会在app.ts里面注入到一个包裹children的ThemeProvider里面。 有没有可能就是因为在入口组件里使用的,才导致taro拿到的config是空? |
有什么反馈吗? |
@ZakaryCode 大佬,有什么反馈吗? |
验证了下,你调用方法太早了,需要在应用启动之后才能正常执行该方法,可以写到组件内调用 |
可是这个是定义的作为主题的,然后注入给ThemeProvider,怎么写到组件内? |
launch 之后再创建 theme,改一下 useChangeTheme 的实现 |
除了app.ts这里以外,useChangeTheme还能放在什么地方,才能让整个app都可以被Provider包裹呢? |
不需要挪动 useChangeTheme 啊,只是改下 theme 就行,不在创建前执行即可 |
这个是模拟器自行转换的,无需在意,它转换单位也是适配了的 |
好的好的。 |
相关平台
微信小程序
复现仓库
https://github.com/thundersdata-frontend/taro-style.git
小程序基础库: 3.0.0
使用框架: React
复现步骤
https://github.com/thundersdata-frontend/taro-style/tree/master/demo
npm run dev:weapp
然后打开微信开发者工具,在console里面就可以看到报错
期望结果
可以正常使用
实际结果
报错: Cannot read property '750' of undefined
环境信息
The text was updated successfully, but these errors were encountered: