첫 λ²μ§Έ μμ²μ κ²°κ³Όλ₯Ό λ λ²μ§Έ μμ² λ±μ μ¬μ©ν΄μΌ νλ κ²½μ°, μ¬λ¬ μμ²μ ν¨κ» μ°κ²°νλ λ°©λ²μ λν μμ λ₯Ό μλ €μ£Όκ±°λ μ½λ μ‘°κ°μ 곡μ ν μ μλ μ¬λμ΄ μμ΅λκΉ?
κ²°κ³Όλ₯Ό μΌλ° μ½μμ²λΌ μ°κ²°ν μ μμ΅λλ€.
axios.get(...)
.then((response) => {
return axios.get(...); // using response.data
})
.then((response) => {
console.log('Response', response);
});
μ΄ μμμ response
λ μμ²μ΄ μ±κ³΅ν κ²½μ°μλ undefinedλ‘ λμμ΅λλ€.
μλμ, μ μν΄μΌ ν©λλ€. return
λ¬Έμ μΌλμ λμμμ€. λΉμ μ μλ§ κ·Έκ²μ λμ³€λ€.
μμ΄μ΄μ΄μ΄
μ΄ κ²½μ° κ°λ³ μ€λ₯λ₯Ό μ΄λ»κ² μ‘μλΌ μ μμ΅λκΉ?
λλ axios κ²μλ¬Όμ λ³΄λΌ λ£¨ν(for)κ° μκ³ κ° μμ²μ΄ κ° λ£¨ν νμ 보λ΄μ§μ§ μμλ€λ κ²μ λ°κ²¬νμ΅λλ€. 루νκ° λλ ν ν¨κ» 보λμ΅λλ€.
μ΄κ²μ λ΄ μ½λμ
λλ€
`
for (let i = 0;i < λ€λ¦;i++) {
tem.start = μκ°(μμ).add(i, 'μΌ').format('YYYY-MM-DD')
tem.end = μκ°(tem.start).endOf('μΌ').format('YYYY-MM-DD 23:59:59')
tem.date = tem.start
// if (V.hasSameValue(title, tem.start, tem.end))continue
V.addEventsToCalendar(ν )
}
addEventsToCalendar: (μ΄λ²€νΈ) => {
axios.post(requestUrl('calendar'), {...event})
.then(res => {
V.eventsRender(V.dataToEvent([res.data]))
μ±κ³΅ν()
})
.catch(μ€λ₯ν)
},
`
@Liaohuanle
λ λΉλκΈ°μμ΄λ―λ‘ κ° μμ
μ΄ λλ λκΉμ§ κΈ°λ€λ¦¬μ§ μμ΅λλ€. 루ν λμ κ°λ¨ν μ¬κ·λ₯Ό μ¬μ©ν μ μμ΅λλ€.
μ΄κ²μ μλνμ§ μλ μ΄μ λ 무μμ λκΉ?
axios.get(...)
.then((response) => {
axios.get(...)
.then((response) => {
console.log('response);
})
})
@alejogamboa λ λ€λ₯Έ μ½λ°± μ§μ₯, μ΄λ»κ² μκ°νμΈμ?
var array = [0,1,2];
axios.get('api/' + array[0]).then(response => {
axios.get('api/' + array[1]).then(response => {
axios.get('api/' + array[2]).then(response => {
alert('done');
});
});
});
λ°°μ΄μ κΈ°λ°μΌλ‘ μ΄λ»κ² μ°κ²°ν©λκΉ?
@jericopulvera μ¬μ©μ μ΄ν΄λ³΄μμμ€.
axios.all([])
for (...) {
arr.push(axios.get("url"));
}
let result = await axios.all(arr);
console.log(res);
μ΄λ―Έ μ¬κΈ°μ μ루μ μ΄ μμ΅λλ€ # 1413
κ°μ₯ μ μ©ν λκΈ
κ²°κ³Όλ₯Ό μΌλ° μ½μμ²λΌ μ°κ²°ν μ μμ΅λλ€.