출저
- 위코드 수업자료
Signup.json
이라는 mock data
를 임의로 만들어서 fetch()로 갖고올때 쓴 코드.fetch("/data/Signup.json", {
method: "GET",
})
.then((res) => res.json())
.then((res) => {
this.setState({
policies: res.policies,
});
});
data폴더
안에 있는 Singup.json
파일을 받아 온다.get
와 post
가 있는데, get이 default method
이기 때문에 생략해도 무방하지만, 협업하는 convention을 따르도록 한다. 그리고, method는 백엔드 개발자가 만든것. get인지 post인지 모르면 백엔드에게 물어봐야한다. 비동기
라고 한다.비동기의 동기화
라고 한다.fetch(`${API}/account/signin`, {
method: "POST",
body: JSON.stringify({
email: this.state.id,
password: this.state.pw,
}),
})
.then((response) => response.json())
.then((result) => {
if (result.message === "SUCCESS") {
this.props.history.push("/Main-haiin");
localStorage.setItem("Token", result.Authorization);
} else {
alert("다시 입력하세요.");
}
});
API
라는 변수에 주소를 할당하고 가져와서 쓴다.참고
access token 저장하기
Local Storage: 해당 도메인에 영구 저장한다.
Session Storage: 해당 도메인의 한 세션에서만 저장한다. 닫으면 data가 날라간다.
Cookie: 해당 도메인에 설정한 날짜까지만 저장한다.