分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

react.js 渲染一个列表的实例

发布时间:2023-09-06 01:12责任编辑:熊小新关键词:js
import React,{Component} from ‘react‘;import ReactDOM from ‘react-dom‘;let users=[ ???{id:1,name:‘老王1‘,age:31}, ???{id:2,name:‘老王2‘,age:32}, ???{id:3,name:‘老王3‘,age:33}]class User extends Component{ ???render(){ ???????return( ???????????<tr> ???????????????<td>{this.props.item.id}</td> ???????????????<td>{this.props.item.name}</td> ???????????????<td>{this.props.item.age}</td> ???????????</tr> ???????) ???}}//在一个组件中,状态越少越好class UserList extends Component{ ???render(){ ???????return( ???????????<table> ???????????????<thead> ???????????????<tr> ???????????????????<th>ID</th> ???????????????????<th>名字</th> ???????????????????<th>年龄</th> ???????????????</tr> ???????????????</thead> ???????????????<tbody> ???????????????{ ???????????????????this.props.user.map((item,index)=>{ ???????????????????return ( ???????????????????????<User item={item} key={index}></User> ???????????????????) ???????????????}) ???????????????} ???????????????</tbody> ???????????</table> ???????) ???}}ReactDOM.render(<UserList user={users}></UserList>,document.querySelector("#root"));

react.js 渲染一个列表的实例

原文地址:http://www.cnblogs.com/null11/p/7551195.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved