zoukankan      html  css  js  c++  java
  • vue axios 中 async + await 使用

    veu axios 中 async + await 使用

    01) 使用 await 

    等待网路请求返回后,才执行后面其他代码

    methods: {
        // 图书详细
        async cliDetail() {
           console.log("本方法开始执行__",new Date().toLocaleTimeString());
           await this.$get(this.$interfacres.getBookDetail, {bookId: 3}).then(res => {
                console.log("await 网路请求返回",new Date().toLocaleTimeString(), res);
            });
    
            console.log("我是daFei_test",new Date().toLocaleTimeString());
        }
    }

    02) 没有使用 await

    如果网络延迟,后面代码照常执行

    methods: {
        // 图书详细
        async cliDetail() {
           console.log("本方法开始执行__",new Date().toLocaleTimeString());
           this.$get(this.$interfacres.getBookDetail, {bookId: 3}).then(res => {         
                console.log("网路请求返回",new Date().toLocaleTimeString(), res);
            });
    
            console.log("我是daFei_test",new Date().toLocaleTimeString());
        }
    }

     03) 对比

  • 相关阅读:
    Hexo博客搭建教程
    windows7如何查看端口被占用
    openshift rhc
    .net面试题精选
    Java垃圾回收机制
    Maven 入门篇(下)
    Maven 入门篇 ( 上 )
    OPENSHIFT MYSQL使用Navicat远程连接
    ci配置smarty手记
    solr多核配置
  • 原文地址:https://www.cnblogs.com/dafei4/p/13253676.html
Copyright © 2011-2022 走看看