利用promise 让 函数按序执行
<template> <div> <el-button @click="btn">按钮</el-button> </div> </template> <script> export default { data() { return {} }, mounted() { }, methods:{ btn() { this.a().then(this.b).then(this.c) }, // async btn(){ // await this.a() // await this.b() // await this.c() // }, a(){ return new Promise(((resolve,reject) => { setTimeout(()=>{ console.log(1) resolve() },3000) })) }, b(){ return new Promise(resolve => { setTimeout(()=>{ console.log(2) resolve() },2000) }) }, c(){ return new Promise(resolve =>{ setTimeout(()=>{ console.log(3) resolve() },1000) }) }, } } </script>