“Comment utiliser Axios” Réponses codées

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 réagit

$ npm install react-axios
Victorious

Comment utiliser Axios Get

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

Comment utiliser 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

Réponses similaires à “Comment utiliser Axios”

Questions similaires à “Comment utiliser Axios”

Plus de réponses similaires à “Comment utiliser Axios” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code