Javascript 我要得到你的承诺

Javascript 我要得到你的承诺,javascript,promise,Javascript,Promise,如何在后端服务器上工作? 或在等待后获得价值。。。。你怎么能等呢 api_get() .then(function (response) { console.log("after response : ", response); // after response : undefined // How do i get value? }) 为了使用,你必须回报一个承诺。您的api_get函数没有返回任何内容,只需在axios

如何在后端服务器上工作? 或在等待后获得价值。。。。你怎么能等呢

api_get()
    .then(function (response) {
         console.log("after response : ", response);
         // after response : undefined
         // How do i get value?
    })
为了使用,你必须回报一个承诺。您的api_get函数没有返回任何内容,只需在axios.get之前添加return

将您的功能更改为:

const api_get = () => {
    return axios.get(url)
        .then(function(response){
            console.log("after api : ", response.data)
            return response
        })
您应该使用axios软件包与后端服务器连接,并在前端进行GET、POST、DELETE、UPDATE等操作。 要安装它,请执行以下操作:-

npm i axios --g

api_get实际上并没有返回承诺链。
npm i axios --g