當(dāng)從 Laravel 控制器返回響應(yīng)時(shí),例如return response()->json([ 'status' => true, 'message' => 'success', 'cat_products' => $cat_products, 'cat_count' => $cat_count]);然后,實(shí)際數(shù)組可在 javascript 端的 response.data 鍵下使用。由于您在 if 語(yǔ)句中進(jìn)行松散比較,因此它與 response.status: 200 進(jìn)行比較,而不是與您"status" => true在 json 響應(yīng)中提供的比較if (response.status == true) { //response.data should contain the data sent as response from controller console.log(response.data); //response.cat_products.forEach(filter); //filter is a function response.data.cat_products.forEach(filter); //this should work}
在 componentDidMount 中設(shè)置狀態(tài)時(shí),React 應(yīng)用程序不顯示來(lái)自 api 的數(shù)據(jù)
MM們
2023-09-28 17:07:54