포스트 방법 Axios의, 배경은 데이터를 수신 할 수 없습니다

  1. 기본 게시 요청 후 요청이 페이로드 매개 변수의 형태로 전송되는 참조 폼 데이터하지 형식을. 이 시점에서 헤드 헤더를 추가합니다.
this.axios.post('url',{
    userCardId: promptValue
}).then(res => {

 })

그림 삽입 설명 여기 그림 삽입 설명 여기
2. 추가 헤더 : { '콘텐츠 유형': '응용 프로그램 / x-www-form-urlencoded를'}; 다음과 같은 결과는, 양식 데이터 오브젝트를 통과했다.

this.axios({
    method:'post',
    url:'url',
    data:{userCardId:promptValue},
    headers:{'Content-Type':'application/x-www-form-urlencoded'},
}).then(res =>{
                      
}) 

그림 삽입 설명 여기 그림 삽입 설명 여기
3. transformRequest 부분을 계속 추가 데이터 변환을한다. 이 때, 후단의 데이터를 수신 할 수있다.

this.axios({
    method:'post',
    url:'url',
    data:{userCardId:promptValue},
    headers:{'Content-Type':'application/x-www-form-urlencoded'},
    transformRequest:[function (data) {
        let ret = ''
        for (let it in data) {
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
         }
            return ret
     }],
 }).then(res =>{
                    
 }) 

그림 삽입 설명 여기 그림 삽입 설명 여기
https://github.com/Gesj-yean/vue-demo-collection 문서화 사용 더 뛰어난 플러그인. 학생들은 대단히 감사합니다 수 있습니다 내 최고 블로그 보는 시간을 갖는다.

게시 27 개 원래 기사 · 원 찬양 4 · 조회수 2832

추천

출처blog.csdn.net/qq_39083496/article/details/89382774