“cara menggunakan axios” Kode Jawaban

Axios

npm i axios
Hurt Herring

Posting Axios

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 bereaksi

$ npm install react-axios
Victorious

cara menggunakan 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

cara menggunakan 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

Jawaban yang mirip dengan “cara menggunakan axios”

Pertanyaan yang mirip dengan “cara menggunakan axios”

Lebih banyak jawaban terkait untuk “cara menggunakan axios” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya