【发布时间】:2021-10-10 21:06:12
【问题描述】:
我使用 express.js 在 localhost:3000 上运行了一个 API,结果如下:
0
_id: "610bcbd9c0ce881847bfd5b6"
__v: 0
1
_id: "610bcc43c0ce881847bfd5b8"
name: "haaa"
title: "data"
title2: "data2"
__v: 0
2
_id: "610bcc5ec0ce881847bfd5ba"
name: "haaa"
title: "data"
title2: "data7"
__v 0
3
_id: "610bcd00303b9a1b041d9d6a"
name: "haaa"
title: "data"
title2: "data7"
__v: 0
当我运行 axios.get 时,我收到一个错误。
app.js 上的代码:
const [data, setData] = useState();
useEffect(() => {
async function fetchmyapi() {
try {
let response = await axios.get('http://localhost:3000/')
setData(response)
console.log(data)
}
catch(error) {
console.log(error)
}
}
fetchmyapi()
}, [])
这是 console.log 中的错误:
Network Error
at node_modules/axios/lib/core/createError.js:1:0 in <global>
at node_modules/axios/lib/adapters/xhr.js:74:24 in handleAbort
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:600:10 in setReadyState
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:395:6 in __didCompleteResponse
at node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:189:10 in emit
at [native code]:null in callFunctionReturnFlushedQueue
有什么问题,我可以使用其他东西而不是 Axios 吗?
【问题讨论】:
标签: react-native express axios localhost