Program/Vue

Vue Axios

하랑파파♡ 2018. 8. 1. 14:20
728x90
반응형
SMALL

  1. 설치
    yarn add axios
    or
    npm install axios --save
     
  2. main.js
    import axios from 'axios'
    Vue.prototype.$http = axios
     
  3. 사용법
    - get 방식

1

2

3

4

5

6

7

8

this.$http

  .get('api_url', { 

params: { 

name'TEST' 

}

   })

  .then(res => {

    console.log(res);

  })

  .catch(error => {

    console.log(error);

  });

Colored by Color Scripter

cs


- post 방식

1

2

3

4

5

6

7

8

9

10

11

12

13

let formData = new FormData();

formData.append('email', this.email);

 

this.$http

  .post('api_url', formData)

  .then(res => {

    console.log(res);

  })

  .catch(error => {

    console.log(error);

  });

Colored by Color Scripter

cs


728x90
반응형
LIST

'Program > Vue' 카테고리의 다른 글

Vue-cli 3에서 eslint 설정  (0) 2018.08.01
vue build 시 쌍따옴표가 삭제되서 에러 날 때(vue.config.js)  (0) 2018.08.01
Vue Cli 설치  (0) 2018.08.01
Window 패키지 관리 Chocolatey  (0) 2018.08.01
Mac Homebrew 설치  (0) 2018.08.01