Here's my code
main.js
// main.js
const calc = require('./calc');
const calcInfo = calc.getCalcInfo();
console.log('calcInfo:', calcInfo); // I expect wait until response data
and calc.js
// calc.js
import axios from 'axios';
const getCalcInfo = async () => {
let resultData = await axios.post('/api/logis/getCalcInfo', {});
console.log('getCalcInfo', resultData);
return resultData;
}
export {
getCalcInfo,
}
result log
calcInfo: Promise {<pending>}__proto__: Promise[[PromiseStatus]]: "fulfilled"[[PromiseValue]]: Object
calc.js:6 getCalcInfo {data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
I expected log "calcInfo" will show axios responsed data. but that's return Promise.
Is there a solution for this issue?
EDIT: thanks for reply! but i'm still have a question.
this is a modified code. same main.js and calc.js
const getCalcInfo = () => {
axios.post('/api/logis/getCalcInfo', {})
.then((result) => {
return result;
});
}
result here:
calcInfo: undefined
so I'm not using async(but axios maybe using). but call getCalcInfo's result is undefined.
why does it work like this?