Ich teste es mit meinem Samsung Android-Gerät
Ich habe alles versucht
Von Postman aus, wenn ich eine Get-Anfrage sende wie „http://127.0.0.1:8000/drinks/“, erhalte ich
Code: Select all
[
{
"id": 1,
"name": "Grape Soda",
"description": "Soda with Grapes"
},
{
"id": 2,
"name": "Orange Soda",
"description": "Soda with Orange"
}
]
Code: Select all
CORS_ORIGIN_ALLOW_ALL = True
Ich habe eine apiCall-Komponente:
Code: Select all
import axios from "axios";
export const apiCall = axios.create({
baseURL: "http://127.0.0.1:8000/drinks/",
timeout: 3000, // optional timeout setting
headers: {
"Content-Type": "application/json",
},
});
Code: Select all
import { StyleSheet, Text, View } from "react-native";
import React, { useEffect, useState } from "react";
import { apiCall } from "../api/apicall";
const DrinksScreen = () => {
const [drinks, setDrinks] = useState([]);
function loadDrinksData() {
apiCall
.get("/drinks/")
.then((drinks) => {
console.log("success!, data: ", data);
return drinks;
})
.catch((error) => {
console.log("error!: ", error);
return error;
});
}
useEffect(() => {
let data = loadDrinksData();
}, []);
return (
drinksScreen
);
};
Was könnte das sein?
Vielen Dank im Voraus
Mobile version