【发布时间】:2020-03-04 09:42:29
【问题描述】:
为了确保存在用户输入的单词,我需要不断提示(while 循环)输入单词,直到单词 API 找到该单词。
我的问题是:如何根据 Axios 调用结果退出 while 循环?
下面是我目前的代码。
const wordApiBaseUrl = 'https://www.dictionaryapi.com/api/v1/references/sd4/xml'
while (true) {
const wordToGuess = prompt('Enter a word:').toLowerCase()
const endPointUrl = `${wordApiBaseUrl}/${wordToGuess}?key=${wordApiKey}`
this.axios.get(endPointUrl).then(res => {
if (res.data.includes('def')) {
break
}
})
}
【问题讨论】:
标签: vue.js while-loop axios