react动态生成列表

在组件的render函数中遍历数组menus[]并且要return返回虚拟Dom对象。

render() {
        return createPortal(
            this.state.visible &&
            <div className={styles.modal}>
                <div className={styles.content}>
                    <ul>
                        {this.props.menus.map((item,index)=>{
                            console.log(index,item.title);
                            return <li   key={index}>{item.title}</li>
                        })}
                    </ul>
                </div>
            </div>, this.node
        )
    }

猜你喜欢

转载自www.cnblogs.com/Oldz/p/12376162.html
今日推荐