解决方案
getInfo() { var _this = this return new Promise((resolve, reject) => { this.getRList(function(res) { _this.regionList = res resolve(_this.regionList) }) }) }, getInfo1() { var _this = this this.getInfo().then(val => { _this.getCList(function(res1) { _this.cityList = res1 _this.privListdata = _this.resetPrivList(val, res1) }) }) },
实践根底
1.async/await应用办法
用Promise来实现。
Promise是ES6的新个性,用于解决异步操作逻辑,用过给Promise增加then和catch函数,解决胜利和失败的状况
示例一:
function2(){ return new Promise((resolve, reject) => { //你的逻辑代码 resolve(/* 这里是须要返回的数据 */) }); } function3(){ return new Promise((resolve, reject) => { //你的逻辑代码 resolve(/* 这里是须要返回的数据 */) });} // 调用 function1(){ this.function2().then(val => { this.function3(); }); }
val为resolve办法返回的数据