![](/img/trans.png)
[英]Vue.JS - Api request - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'quote')
[英]'Uncaught TypeError: Cannot read properties of undefined (reading 'then')' on API request
當我向 API 發出請求時,我的頁面停止了,我收到了內容並將其打印在控制台上。
function getFilms() {
fetch('https://ghibliapi.herokuapp.com/films')
.then((response) => response.json())
.then((data) => {
console.log(data);
return data;
});
}
export default getFilms;
我嘗試使用隱式返回並在“.them”之外返回但沒有成功。
我收到未定義的消息,因為調用者沒有收到 API 的返回。通過返回獲取解決。
function getFilms() { return fetch('https://ghibliapi.herokuapp.com/films').then((response) => response.json()).then((data) => { console.log(data); }); } export default getFilms;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.