Programing

Axios 및 VueJS, 함수(응답)가 목록을 설정하지 않음

c10106 2022. 4. 18. 20:26
반응형

Axios 및 VueJS, 함수(응답)가 목록을 설정하지 않음

자료를 받아서 변수에 추가해달라는 요청이 있는데,

사용할 때:

.then(function(response) {
    this.persons = response.data;
});

할당되지 않음response.datathis.persons하지만 내가 다음을 할 때:

.then(response => this.persons = response.data);

그것은 그것을 사용해도 좋다고 할당한다.js fiddle을 참조하십시오.

https://jsfiddle.net/trhhtyxr/2/

여기서 설명했듯이 화살표 구문이것, 인수, 수퍼 또는 new.target을 바인딩하지 않는다.화살표 기능은 항상 익명이다.이러한 함수 표현은 비방법 함수에 가장 적합하다.

의 범위thisfunction() block 내부의 변경사항 현재 실행 중인 기능은 아니지만, 화살표 기능은,this현재 실행 중인 기능만 참조한다.

참조URL: https://stackoverflow.com/questions/42039714/axios-and-vuejs-functionresponse-is-not-setting-a-list

반응형