在这里设置了 resData的值
而后在回调函数里面,这个方法里面通过this.data.resData 来获取,发现是拿不到的
**Promise.resolve(value)**
方法返回一个以给定值解析后的Promise
对象。假如这个值是一个 promise ,那么将返回这个 promise ;假如这个值是thenable(即带有"then"
方法),返回的promise会“跟随”这个thenable的对象,采用它的最终状态;否则返回的promise将以此值完成。此函数将类promise对象的多层嵌套展平。
所以这里我是这么写的,完美处理这个问题!
这个方法是我要调用的方法,从后端接口获取的数据的方法
getOrderByStudentId: function (mac) { var that = this return new Promise(function (resolve, reject) { https.getOrderByStudentId( { mac: mac, studentId: that.data.studentId }) .then(res => { //hasOwnProperty 是用来判断该对象里面有没有data属性 ,有就返回true. resolve(res.hasOwnProperty('data')) }) }) },
那么在我们的回调方法里面是如何调用的呢,请看下面代码片段
that.getOrderByStudentId(mac.result).then(resData => { console.log(resData)//这个就是从上个接口返回的数据})