已经执行到黄色部分了,res['data'].itemMaterialType=3,
this.itemMaterialType = res['data'].itemMaterialType; 这句话已经执行了,为什么this.itemMaterialType一直是undefined;理论上this.itemMaterialType=3才对啊;
以下是封装的方法,
async searchData() {
this.itemMaterialType = '4';
await this.api.Dispatch.queryProcessDetailByProcessId({
processId: this.processId
})
.then(res => {
this.data = res['data'];
this.isFeedMaterial = res['data'].isFeedMaterial.toString();
this.itemMaterialType = res['data'].itemMaterialType;
});
}
queryProcessDetailByProcessId: async (option) => await this.http.getByPromise('/api/ScheduleProcess/GetProcessDetail', option),
async getByPromise(url: string, params: {}) {
return await this.http.get(this.domain + url, { observe: 'body', params: params })
.toPromise();
}
1 .then 发生在获取数据之后, 无需使用async await
2 获取res 后 取值 可以直接 使用简写使用点语法 res.data
3 api 中 已经转换成 promise 后 resolve(数据) reject(cache Error) 无需强制转成 同步