본문 바로가기
카테고리 없음

[React] 1일차

by ProSeraphina 2020. 11. 17.

Spring: ReactController에서 주소 지정하는 부분
index.html에서 css 링크를 바꿨다.
axios를 추가했다. 외부데이터를 불러오는 역할이라고 함.

 

▶app.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
import React,{Component} from 'react'
import axios from 'axios'
 
class App extends Component{
  constructor(props) {
    super(props);
    this.state={
      recipe:[],
      detail:{},
      totalpage:1,
      page:1
    }
  }
  componentDidMount() {
    axios("http://localhost/web/recipe/list.do",{
      params:{
        page:1
      }
    }).then(response=>{
      this.setState({recipe:response.data})
    })
  }
  render() {
    const html=this.state.recipe.map(m=>
        <div className="col-md-3">
          <div className="thumbnail">
              <img src={m.poster} alt="Lights" style={{"width":"100%"}}/>
                <div className="caption">
                  <p>{m.title}</p>
                </div>
          </div>
        </div>
    )
    return(
        <div className={"row"}>
          {html}
        </div>
    )
  }
}
export default App;
cs

 

하단 Terminal 탭에서 npm start를 입력하면 링크 주소가 뜬다. 클릭!

결과화면. 한글 인코딩이 아직 안되는 것 같아서 수정할 예정.

댓글