The call is asynchronous meaning that you have to wait for your request to complete (or more accurately your promise from axios.get()
to resolve) and do something with the result. Your code right now runs synchronously.
colorList = axios.get(colors).then(result =>{
console.log(result)
});
EDIT: Or as a comment above noted, use an async/await setup. Keep in mind that you can't use await in top level code, it can only be used inside an async function
(async () => {
try {
const colorCodes = await axios.get(colors);
} catch (e) {
// handle error
}
})()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…