Taro中的Cannot read property 'map' of undefined

import Taro, { Component } from '@tarojs/taro'
import PropTypes from 'prop-types'
import { View, Image } from '@tarojs/components'
import './index.scss'

class Index extends Component {
    render() {
        return (
            
                {
                    this.props.prolist.map(item => (
                      Taro.navigateTo Taro.switchTab Taro.redirectTo
                         {
                            Taro.navigateTo({
                                url: '/pages/detail/index?proid=' + item.proid
                            })
                        }}>
                            
                                
                            
                            
                                {item.proname}
                                {item.sales} / {item.stock}
                                ¥{item.price}
                            
                        
                    ))
                }
            
        )
    }
}

Index.propTypes = {
    prolist: PropTypes.array
}

export default Index

报错:Cannot read property ‘map’ of undefined

Taro中的Cannot read property 'map' of undefined_第1张图片
因为初始化时this.props.prolist是undefined
所有要判断this.props.prolis是不是undefined,直到有值才渲染

解决方案
【1】
Taro中的Cannot read property 'map' of undefined_第2张图片
【2】
Taro中的Cannot read property 'map' of undefined_第3张图片

如有解释不周,请谅解。。。

你可能感兴趣的:(Taro中的Cannot read property 'map' of undefined)