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

render 使用 if 语句 无法正确渲染 #869

Closed
SzHeJason opened this issue Oct 17, 2018 · 1 comment
Closed

render 使用 if 语句 无法正确渲染 #869

SzHeJason opened this issue Oct 17, 2018 · 1 comment
Assignees

Comments

@SzHeJason
Copy link

问题描述
render 使用 if 语句 无法正确渲染、

复现步骤

import Taro, { Component } from '@tarojs/taro'
import PropTypes from 'prop-types'
import { View,Text } from '@tarojs/components'

import './index.scss'

export default class DocsHeader extends Component {
  render () {
    const { title } = this.props
    const ss = true
    let des 
    if (ss) {
      des = <Text>111</Text>
    } else {
      des = <Text>222</Text>
    }

    return (
      <View className='doc-header'>
        {des}
        <View className='doc-header__title'>111{title}</View>
      </View>
    )
  }
}

DocsHeader.defaultProps = {
  title: '标题'
}

DocsHeader.propTypes = {
  title: PropTypes.string
}

报错信息
image

系统信息

  • 操作系统: MacOs
  • Taro 版本 1.0.7 || 1.1.0-beat8
  • Node.js 版本 10
  • 报错平台 weapp
@yuche yuche self-assigned this Oct 17, 2018
@yuche
Copy link
Contributor

yuche commented Oct 17, 2018

taro 在编译前会把没有意义的条件判断都删除,所以你这部分代码实际上等于

let des 
{
      des = <Text>111</Text>
}

而这样是没有意义的延时赋值,具体情况可以到 #550 追踪这个问题的进展。

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

2 participants