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"); }) }