“So verwenden Sie Axios” Code-Antworten

Axios

npm i axios
Hurt Herring

Axios Post

const axios = require('axios');
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Gleaming Goat

Axios

// npm install axios
const axios = require('axios');

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });

// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
    // always executed
  });  

// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
  try {
    const response = await axios.get('/user?ID=12345');
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}
code fighter

Axios reagieren

$ npm install react-axios
Victorious

Wie man Axios verwendet

const req = async () => {
  const response = await axios.get('https://dog.ceo/api/breeds/list/all')
  console.log(response)
}
req() // Calling this will make a get request and log the response.
Grotesque Gaur

So verwenden Sie Axios

const [data, setData] = useState([]);
  const getApi = async () => {
    const url = await axios.get(
      "http://quencies.alshumaal.com/api/RCAs/getallRcas.php"
    );
    setData(url.data.getallRCAs);
  };
  useEffect(() => {
    getApi();
  }, []);
Blue Baboon

Ähnliche Antworten wie “So verwenden Sie Axios”

Fragen ähnlich wie “So verwenden Sie Axios”

Weitere verwandte Antworten zu “So verwenden Sie Axios” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen