我試圖實現終極版動作與使用陣營本地異步調用檢索一些JSON數據。我把函數fetchRestaurant()無處不在內部的元件,但我仍然得到這個錯誤:用減速異步調用不起作用
無法讀取屬性「類型的不確定。
這裏的內部動作的代碼/ restaurant.js
export function setFetchedRestaurant(restaurants){
return Object.assign({ type: types.SET_FETCHED_RESTAURANT, restaurants:restaurants });
}
export function fetchRestaurant(){
var restaurants;
fetch('https://appetizing.000webhostapp.com/connect.php').then((response) => response.text()).then((responseText) => { dispatch(setFetchedRestaurant(JSON.parse(responseText)));}).catch((error) => {console.warn(error);});
}
,這是我到fetchRestaurant()函數我的組件內部呼叫:
componentDidMount(){
this.props.fetchRestaurant();
}
錯誤,但如果我用** console.log(response.text)打印響應; **與真實響應不同 – userfi
好的,如果你的console.log(響應)怎麼辦?那應該給你整個迴應對象嗎? – therewillbecode
我這樣做,答覆是空白的...... – userfi