javascript - useQuery : 没有获取数据
问题描述
当我记录未定义的数据时,但是当我登录时,我会看到数据。知道为什么吗?
const {data}= useQuery('get-todos',()=>{axios.get('http://localhost:8080/todos').then(res => res.data)})
解决方案
您的查询函数需要从 axios 返回承诺:
const {data}= useQuery('get-todos',() => {
return axios.get('http://localhost:8080/todos').then(res => res.data)
})
推荐阅读
- python - “conda install”与“-c anaconda”和没有它的区别
- git - 在同一分支上合并两个 GIT 提交
- aop - guice AOP是如何实现的?
- c# - 将 Grid.RowDefinition 高度绑定到 Xamarin 中的网格宽度
- terraform - Can terraforms null_resource use timeouts blocks?
- php - mysqlnd 为与远程主机的所有连接提供“权限被拒绝”
- javascript - Card not rotating on hover to reveal the backside
- python - How can a Python Microservice verify requests using a JWT in an Authorization header?
- javascript - Vue / Jest“无法读取未定义的属性'组件'”
- firebase - Google Firebase 实时数据库和承诺