2017-12-20 13 views
-2

vue-resource를 사용하여 아래의 서버 호출을 수행하는 방법을 알아 내려고하고 있습니다. 헤더를 설정하고 뷰를 사용하여 데이터를 전송하는 방법을 나는 확신하지 $ http.postvue js는 vue-resource를 사용하여 서버 호출을 작성합니다.

jQuery.ajax({ 
url: "http://url/", 
type: "POST", 
headers: { 
    "Content-Type": "application/json; charset=utf-8", 
}, 
contentType: "application/json", 
data: JSON.stringify({ 
    "email": "foo", 
    "password": "bar 
}) 

})

+2

어떻게 실제로 [설명서를 읽기]에 대한 (https://github.com/pagekit/vue-resource/blob/develop/docs/http.md)? – herrbischoff

답변

0

당신은 그냥 할 수 있어야한다 :.

Vue.http.post('http://dev-api.languagelink.com/api/auth/login', { 
    email: '[email protected]', 
    password: 'foobar', 
}).then(res => { 
    // Handle success response 
}) 

vue-을 리소스가 자동으로 Content-Type 헤더를 설정하고 페이로드를 JSON으로 문자열 화합니다. 이 같은

0

시도 뭔가 :

this.$http.post('/url', data, { 
    headers: { 
     'Content-Type': 'application/json; charset=utf-8' 
    } 
}).then(res => { 
//do the stuff 
});