【发布时间】:2021-01-06 20:09:22
【问题描述】:
我目前仍在学习使用 React Native。
我想要做的是将限制值更新为 1,这样它会破坏 while 循环,但我不确定如何执行它,因为我无法从 .then() 内部更新值在 Axios POST 调用中。 很高兴有人能指出任何处理此问题的方法。感谢您的帮助。
var limit = 0;
while (limit == 0) {
running = running + 20;
console.log("restart");
postDataCalories = {
"query": `${running} minutes run and ${walking} minutes walking`,
"gender":"male",
// "nf_calories": 363.62,
"weight_kg":63.5,
"height_cm":167.64,
"age":30
};
console.log(`${running} minutes run and ${walking} minutes walking`);
axios.post('https://trackapi.nutritionix.com/v2/natural/exercise', postDataCalories, axiosConfig2)
.then((res3) => {
console.log("exercise RESPONSE RECEIVED: ", res3);
let caloriesFood = res2.data.foods[0].nf_calories;
let caloriesExercise = res3.data.exercises[0].nf_calories;
let caloriesDifferences = caloriesFood - caloriesExercise;
console.log("hi " + caloriesDifferences);
if (caloriesDifferences < 50){
console.log('done');
limit = 1;
} else {
console.log('nope');
}
})
}
【问题讨论】:
标签: react-native axios