Axios request question: can't you get what is written by the then method? Or how to write the data returned by response?

when I am developing, I will directly

export let getSliders = ()=>{
  return axios.get("/sliders");
};

you can return the data to the component, but

export let getSliders = ()=>{
axios.get("/sliders").then(response=>{
    console.log(response);//
  }).catch((err)=>{
    console.log(err);
  })

};

this is how it is called in the component

 async getSlider(){
          this.sliders= await getSliders();
        },

how can you not get it when you write it later with the then method? Or how to write the data returned by response? Ask for guidance

Mar.05,2021

export let getSliders = ()=>{
  return axios.get('/sliders');
};

just use this again, and there is also a promise after await.


if you use await, shouldn't your data already be in this.sliders
if you want to use then, then go directly

 async getSlider(){
    return await getSliders();
 }

as to why you can't get the data, because your async function does not return a value, it will resolve a undefined as the value, of the fulfilled status of the promise, so you can definitely not get the data. The data is already in the this.sliders
https://codeshelper.com/a/11.. If you need to read this article, you can learn about promise

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd853e-310c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd853e-310c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?