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

[taro-v3.0.0.beta.0]Taro.pxTransform中的taro.config拿不到值 #5742

Closed
shenghanqin opened this issue Mar 19, 2020 · 6 comments
Closed

[taro-v3.0.0.beta.0]Taro.pxTransform中的taro.config拿不到值 #5742

shenghanqin opened this issue Mar 19, 2020 · 6 comments
Assignees

Comments

@shenghanqin
Copy link
Collaborator

问题描述

复现步骤

在组件中使用的Taro

/**
 * 这段注释后可以贴代码
 * 提供完整可复现的代码和整理好代码格式,有助于我们快速定位问题,节省你我时间
 * 代码提供不全或代码格式混乱的 issues 【有可能会被忽略】
 * 
 * 查看如何插入代码:https://coding.net/help/doc/project/markdown.html#i-5
 */
// 这是taro核心代码
const pxTransform = function (size) {
  const { designWidth } = taro.config
  return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
}

// 这是我用到的地方,源码:https://raw.githubusercontent.com/shenghanqin/quickly-mask/feature/next-react-20200213/taro/src/components/taro-cropper/index.tsx
const finishStyle: CSSProperties = {
        position: 'absolute',
        display: 'inline-block',
        color: themeColor,
        textAlign: "right",
        fontSize: Taro.pxTransform(32),
        bottom: Taro.pxTransform(30),
        right: Taro.pxTransform(30),
      };

期望行为

期望能正常使用这个转换

报错信息

Uncaught TypeError: Cannot read property 'designWidth' of undefined
    at Object.pxTransform (index.js?c00c:54)
    at TaroCropperComponent.render (index.tsx?8f0a:530)
    at finishClassComponent (react-dom.development.js?61bb:17176)
    at updateClassComponent (react-dom.development.js?61bb:17129)
    at beginWork (react-dom.development.js?61bb:18624)
    at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:184)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:236)
    at invokeGuardedCallback (react-dom.development.js?61bb:289)
    at beginWork$1 (react-dom.development.js?61bb:23234)
    at performUnitOfWork (react-dom.development.js?61bb:22178)

系统信息

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

@taro-bot
Copy link

taro-bot bot commented Mar 19, 2020

CC @Littly

@taro-bot
Copy link

taro-bot bot commented Mar 19, 2020

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Mar 19, 2020

CC @yuche

@fwh1990
Copy link

fwh1990 commented Aug 12, 2020

为什么项目config中已经配置了designWidth,到这边使用pxTransform的时候又要开发者指定一次?这不应该是Taro内部把控吗?

@tourze
Copy link
Contributor

tourze commented Nov 1, 2020

为什么项目config中已经配置了designWidth,到这边使用pxTransform的时候又要开发者指定一次?这不应该是Taro内部把控吗?

同样有这个疑惑,有点诡异。

@aoarashi1988
Copy link

aoarashi1988 commented Feb 26, 2021

这个改动造成了多端api行为的不一致,是明显有问题的
而且这个taro.config在2.x的时候是可以取到值的,解决问题的思路难道不是弄明白为什么这个值取不到了,而不是强行要求使用这个api的开发人员多加一个参数吗?

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

6 participants