Taro: 列表渲染自定义组件时,如果自定义组件中包含子组件(自定义),子组件无法获取props的值

Created on 12 Jun 2018  ·  10Comments  ·  Source: NervJS/taro

index.js

import Taro, { Component } from '@tarojs/taro'
import { View,Text} from '@tarojs/components'
import  Test from '../../components/Test/Test'
export default class Index extends Component {
  constructor () {
    super(...arguments)
    this.state = {
      testList:[
        'nell',
        'add',
        'nidk'
      ]
    }
}
 render () {
    return (
      <View>
        {
            this.state.testList.map(item=>{
              return (
                <Test info={item} key={item} />
              )
            })
        }
     </View>
   )
}

test.js

import Taro, { Component } from '@tarojs/taro'
import './Test.scss'
import Ico from '../Icon/Icon'
import { View } from '@tarojs/components';

export default class Test extends Component {
    static defaultProps = {
        hasMore: true
    };
  render () {
      return (
          <View className='doctor-box'>
              <Ico type='right' />
              <View className='hint-font__small'>{this.props.info}</View>
          </View>
      )
  }
}

icon.js

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

export default class Ico extends Component {
  render () {
      return (
          <View className={'icon-box icon-'+ this.props.type} />
      )
  }
}

编译后在小程序端的效果是
image
Icon 组件获取不到props的type,这种现象只在列表渲染自定义组件时出现,单个渲染时不会出现

Most helpful comment

还在关注这个 issue 的朋友麻烦试一下 0.0.67,应该能解决这个问题

All 10 comments

看了一下不能复现,更新一下新版本试试?

https://github.com/xuxiaoxiao312/taro-demo
创建了一个测试项目,现在是最新版本,问题还是存在

的确是有这个问题,非常感谢创建的 demo,我们正在修复中。

我也遇到了相同的问题

+1

正在跟进处理

除了无法获取 props 值外,连生命周期、任何执行方法等都无法执行,只可以渲染静态数据,这个问题 mpvue 也有

生命周期、方法无法执行的问题解决了吗?

还在关注这个 issue 的朋友麻烦试一下 0.0.67,应该能解决这个问题

经测试,已修复,可以关闭了~

Was this page helpful?
0 / 5 - 0 ratings