vue 同步请求
vue 同步请求 Aa_duidui 于 2021-08-02 11:22:13 发布 4467 收藏 3 分类专栏: vue 版权 vue 专栏收录该内容 10 篇文章0 订阅 订阅专栏 同步请求执行的顺序 async-await 挂上的才是同步,没挂上的还是异步 async 方法名(){ await 请求方法(参数).then(res=>{ //xxx }); } //或者 async 方法名(){ var res = await 请求方法(参数); //xxx } 调用同步的方法,会有以下几种情况 1.没有同步(异步请求) 请求结果 111 333 444 222 f1(){ console.log(111) this.f2(id); console.log(444); } f2(id){ r1(id).then(res={ console.log(222); }) console.log(333); } 2.调用的方法同步请求 打印结果 111 444 222 333 f1(){ console.log(111) this.f2(id) console.log(444) } async f2(id){ await c1(id).then(res=>{ conole.log(222); }) console.log(333); } 3.所有方法全是同步 打印结果 111 222 333 444 async f1(){ console.log(111) await this.f2(id) console.log(444) } async f2(id){ await c1(id).then(res=>{ conole.log(222); }) console.log(333); } 一个方法里面多个需要同步请求 async f1(){ var v1 = await this.c1(id); var v2 = await this.c2(v2.id); } ———————————————— 版权声明:本文为CSDN博主「Aa_duidui」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/Aa_duidui/article/details/119321090
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了