vue在一个方法执行完后执行另一个方法
用Promise.all来实现。
Promise是ES6的新特性,用于处理异步操作逻辑,用过给Promise添加then和catch函数,处理成功和失败的情况
ES7中新提出async搭配await,建议使用async搭配await。
使用方法:async/await使用方法
示例:
function fun1(){ return new Promise((resolve, reject) => { /* 你的逻辑代码 */ console.log("1"); }); }, function fun2(){ return new Promise((resolve, reject) => { /* 你的逻辑代码 */ console.log("2"); }); }, function fun3(){ return new Promise((resolve, reject) => { /* 你的逻辑代码 */ console.log("3"); }); }, /* 调用 */ function run(){ Promise.all([ this.fun1(), this.fun2(), this.fun3() ]).then(res => { /* 你的逻辑代码 */ console.log("run"); }) }