18910140161

JavaScript-无法使用Axios获取数据-堆栈溢出

顺晟科技

2022-10-18 13:51:07

168

我正在努力学习我想要建立的基本反应。鸡尾酒页面,允许用户搜索特定的鸡尾酒我使用过CocktailsDB API,但尝试使用Axios但是当我试图搜索时,结果不会出来,因为没有数据。我不知道这个问题的根源。图象


顺晟科技:

这个问题是因为这里有一个换行符:https://github.com/matansofer/cocktail-bar/blob/e21c5cc266c23cb2e47e26ea31de102ef26d791f/components/search/search.js#l27

尤其是这条线:

axios
      .get(`https://thecocktaildb.com/api/json/v1/1/search.php?s=
      ${term}`)  //pay attention is the letter next to digit 1

如果您查看网络请求,您将看到搜索词前面有一串空格。

invalid search term

如果将该行更改为:

 axios
      .get(`https://thecocktaildb.com/api/json/v1/1/search.php?s=${term}`)

它工作正常:

enter image description here

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航