MyPage.vue

김형우·2021년 12월 24일
0

vue.js

목록 보기
20/30

백엔드로 데이터를 전송하는 명령어

get(조회), post(추가), put(수정), delete(삭제)

  • 조회 : await this.axios.get(url, {headers:headers});

  • 추가 : await this.axios.post(url, body, {headers:headers});

  • 수정 : await this.axios.put(url, body, {headers:headers});

  • 삭제 : await this.axios.delete(url, {headers:headers, data:{ }});

MyPage.vue

data(){
       return{               
           username : '',
           usermail : '',
           dom      : '',
           token    : sessionStorage.getItem("TOKEN"),
        }
    },

// 백엔드
const url = '주소'
const headers = {
	"Content-Type":"application/json",
    	"TOKEN" : this.token     
                };
    // headers가 먼저 들어가기 떄문에 검증 후 토큰의 유효성이 검증되지 않으면 
    // body를 궂이 받을 필요가 없기떄문에 headers에 토큰을 넣어서 보냄
const body = {
	username : this.username,
	usermail : this.usermail+"@"+this.dom
    	}
               
const response = await this.axios.put(url, body, {headers:headers});
                console.log(response);
profile
The best

0개의 댓글