-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002News.js
78 lines (52 loc) · 1.78 KB
/
0002News.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import React from 'react';
import logo from '../assets/images/dlrb.jpg';
// 模块化引入图片
import '../assets/css/index.css';
class News extends React.Component{
constructor(props){
super(props);
// {}绑定数据
this.state = {
msg : '新闻',
// 循环数据要加key
list:['1111' , '2222' , '3333'],
list2:[<h2 key = '1'>我是一个h2</h2>,<h2 key = '2'>我是一个h2</h2>],
list3:[
{title:'新闻1111'},
{title:'新闻2222'},
{title:'新闻3333'},
{title:'新闻4444'}
]
}
}
render(){
// 外部循环数据方式,循环数据要加key
let listResult = this.state.list.map(function(value , key){
return <li key = {key}>{value}</li>
})
return(
<div className = "news">
{this.state.msg}
<img src = {logo}/>
{/* 模块化引入图片 */}
<img src = {require('../assets/images/dlrb.jpg')} />
<img src = "https://www.duitang.com/blog/?id=828465168.jpg" />
<hr/>
{this.state.list2}
<hr/>
<ul>
{listResult}
</ul>
<hr/>
{/* 内部循环数据方式,循环数据要加key */}
{
this.state.list3.map(function(value ,key){
return (<li key = {key}>{value.title}</li>)
}
)
}
</div>
)
}
}
export default News;