내가 웹 응용 프로그램에서 Axios의을 사용하여 GET 요청을 만들어 함께 요청 오류를 처리? 감사합니다. .자신의 PARAMATERS
1
A
답변
2
당신은 상황에서 그들을 유지하기 위해 매개 변수를 통해 (폐쇄) 닫을 수 :이 테스트되지 않았습니다,
function myWrapper() {
const params = {
a: 'a',
b: 'b'
}
axios({
method: 'get',
url: "example.com",
params: params
})
.then((response) => {
// you have access to params here
console.log(params.a);
//do stuffs
})
.catch((error) => {
// you have access to params here
console.log(params.a);
// need params._id here ?!!
})
}
주하지만 작업 여기
을해야 실행 예이다 :
function myWrapper() {
const params = {
a: 'a',
b: 'b'
}
axios({
method: 'get',
url: "example.com",
params: params
})
.then((response) => {
// you have access to params here
console.log(params.a);
//do stuffs
})
.catch((error) => {
// you have access to params here
console.log('error', error.message);
console.log('params!!', params);
// need params._id here ?!!
})
}
myWrapper();
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.1/axios.js"></script>
+0
문제는 내가 다른 prams 요청을 여러 번, 나는 두 번째 요청이 완료되기 전에 첫 번째 매개 변수를 무시할 것이라고 두렵다는 것입니다? –
+0
매개 변수를 함수에 전달하십시오. 각 호출은 새로운 컨텍스트를 얻을 것이다 –
+0
아, 고마워. –
그는 함수 호출 밖에서 params? – evolutionxbox
요청을 여러 번 사용하고 요청이 완료되기 전에 덮어 쓸 수 있으므로 비동기로 유지해야합니다. –
흠, params 위의'폐쇄 '는 여기서 일하지 않을 것입니까? –