BoardOne.vue_2

김형우·2021년 12월 29일
0

vue.js

목록 보기
24/30

이전글, 다음글 (GET) + 조회수 증가 (PUT)

1. url / headers / response

async handlePrev(){
    const url = `/board/prevno?cno=${this.no}`;
    const headers = {"Content-Type":"application/json" };
    const response = await this.axios.get(url, {headers:headers});
  • 조회 : await this.axios.get(url, {headers:headers});

2. response 받은 값

  • /board/prevno?cno=${this.no}에서 처리 한 결과값
  • console.log(response);
    : response.data.no : 6 : this.no의 처리결과 = 6
    : response.data.status : 200 : 백엔드에서 잘 처리함

3. 마무리

  • if문으로 response.data.status : 200 일때를 정하고
    다시 if문을 한번 더 써서 이전 게시글이 없을 경우를 대비한다.

  • if(response.data.no <= 0) { alert('이전글이 없습니다.'); }
    : response 받은 값이 0또는 0보다 작을 경우 오류 메세지를 띄운다.

  • else{ this.no = response.data.no;
    : 그러하지 않을경우, 즉 이전글이 있는경우
    this.no현재 글 번호를
    response.data.no url 에서 처리 후 재전송 받은 번호로 바꾼다.

  • 이후 해당번호를 주소창에 던진다.

this.$router.push({
	name : 'BoardOne',
    	query : {bno:1, no:this.no}
        })
  • 해당 주소창의 화면을 가져온다.
    this.handleData();

조회수 증가

1. url / headers / response

async handleHit(){
	const url = `/board/updatehit?no=${this.no}`;
    	const headers = {"Content-Type":"application/json"};
        const response 
        	= await this.axios.put(
                    url,
                    { },
                    {headers:headers} 
                );

2. 마무리

if(response.data.status === 200){
	console.log('조회수 증가 성공');
   	} 
profile
The best

0개의 댓글