이전글, 다음글 (GET) + 조회수 증가 (PUT)
async handlePrev(){
const url = `/board/prevno?cno=${this.no}`;
const headers = {"Content-Type":"application/json" };
const response = await this.axios.get(url, {headers:headers});
/board/prevno?cno=${this.no}
에서 처리 한 결과값console.log(response);
response.data.no : 6
: this.no의 처리결과 = 6response.data.status : 200
: 백엔드에서 잘 처리함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();
조회수 증가
async handleHit(){
const url = `/board/updatehit?no=${this.no}`;
const headers = {"Content-Type":"application/json"};
const response
= await this.axios.put(
url,
{ },
{headers:headers}
);
if(response.data.status === 200){
console.log('조회수 증가 성공');
}