【问题标题】:Determine if Axios request is done判断axios请求是否完成
【发布时间】:2017-12-12 23:07:13
【问题描述】:

有没有什么方法可以确定如下的 Axios 请求是否收到了答复并完成了?

axios.get('/api')
.then(response => this.data = response.data);

【问题讨论】:

    标签: json vue.js axios


    【解决方案1】:

    是的,这是一个承诺,你可以参考和then它:

    var req = axios.get('/api')
                   .then(response => this.data = response.data);
    

    现在我想对它的完成做出反应:

    req.then(x => console.log("Done!"));
    

    或者将该状态保存在外部:

    var isReqDone = false;
    req.then(x => isReqDone = true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 2014-12-24
      • 2019-01-07
      • 2013-02-21
      • 2010-10-15
      • 2019-07-14
      相关资源
      最近更新 更多