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

Created on 14 Jan 2019  ·  4Comments  ·  Source: NervJS/taro

问题描述
特定情况下(见下图), 微信页面报警告:
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>
    )
  }
}

Most helpful comment

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

All 4 comments

欢迎提交 Issue~

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

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

Good luck and happy coding~

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

CC @Chen-jj

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

问题需要close么

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhuxianguo picture zhuxianguo  ·  3Comments

leafchao picture leafchao  ·  3Comments

Zchary-Ma picture Zchary-Ma  ·  3Comments

fuyue111 picture fuyue111  ·  3Comments

chankamlam picture chankamlam  ·  3Comments