ts 怎么返回 axios 获取的值

```
export function hot(): any {
axios
.get('url')
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
return data;
}
'''
最后怎么给data赋值 response.data呢

return response.data

直接return response

看了一下你们的讨论,之所以data为undefined,是因为axios then()为异步执行,但是你的console.log在主进程,因此执行console的时候axios then()还没回调,此时data就是undefined了。那么如果你想获取到data再打印的话,可以使用async await。首先将里面的axios放在一个return new Promise()里面,里面的axios方法的then里面resolve出响应信息,再在其他的方法里面使用时,该函数需要async修饰,如async function getBasicData(),函数里面为
let data = await hot()
......

这样能保证data获取到值后往下执行,这时候再打印就不会是undefined了。
如果不清楚,可以私聊问我,帮助实现

当然有一种最简便的办法就是把需要依赖data的操作放入一个异步宏任务里面,比如
setTimeout(()=>{
console.log(data)
},200)
这是利用js的事件循环机制,宏任务在微任务之后执行。