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

微信端警告: 请给页面提供初始 state 以提高初次渲染性能!Cannot read property 'triggerEvent' of undefined #1907

Closed
Lionad-Morotar opened this issue Jan 14, 2019 · 4 comments
Assignees

Comments

@Lionad-Morotar
Copy link

问题描述
特定情况下(见下图), 微信页面报警告:
image

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

export default class TestPage extends Component {

  config = {
    navigationBarTitleText: 'echarts-for-weixin 示例项目',
  }

  static defaultProps = {
    onGetStyles: () => { return {} },
  }

  render () {
    return (
      <View
        className='echarts'
        style={{...this.props.onGetStyles()}}
      >
      </View>
    )
  }
}

系统信息

  • 操作系统: [Windows 10]
  • Taro 版本 [v1.2.4]
  • Node.js 版本 [10.4.0 - c:\program files\nodejs\node.EXE]
  • 报错平台 [weapp]

补充信息
若采用这种写法则不会报警告:

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

export default class TestPage extends Component {

  config = {
    navigationBarTitleText: 'echarts-for-weixin 示例项目',
  }

  render () {
    const {
      onGetStyles = () => { return {} },
    } = this.state

    return (
      <View
        className='echarts'
        style={onGetStyles()}
      >
      </View>
    )
  }
}
@taro-bot
Copy link

taro-bot bot commented Jan 14, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@luckyadam
Copy link
Member

onGetStyles 是需要从外面传进来么,如果不需要就放到组件内部
如果需要传进来,暂时先在 render 里给 this.props.onGetStyles 执行的地方加一个容错吧
defaultProps 目前对函数处理有点问题

@taro-bot
Copy link

taro-bot bot commented Jan 14, 2019

CC @Chen-jj

@Lionad-Morotar
Copy link
Author

@luckyadam 谢谢 你们的回复很及时 hhhh

问题需要close么

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