Welcome

首页 / 脚本样式 / Vue / Vue等待异步执行之后在继续执行的实现

export default {

name: 'HelloWorld',

props: {

msg: String

},

mounted() {

var vm = this;

vm.loaddata();

},

methods: {

async loaddata() {

var vm = this;

await vm.dowork();

console.log("C");

},

async dowork() {

var vm = this;

console.log("A");

await new Promise((resolve, reject) => {

vm.sayhello();//要执行的其它操作

resolve();

});

console.log("B");

},

sayhello() {

console.log("Say Hello.");

}

}

}