一: 示例代碼
async created() {
// 下拉數據
const keepTypeList = await getToolKeepTypeList()
this.keepTypeList = keepTypeList.data
const machineSpecList = await getMachineList()
this.machineSpecList = machineSpecList.data
await this.getList();
},
// 數據加載
async getList() {
this.loading = true;
await listData(this.queryParams).then(response => {
const data = response.rows
for(const item of data){
for(const eve of this.machineSpecList){
if(item.tksTmtid == eve.key){
item.tksTmtid = eve.value
}
}
for(const eve of this.keepTypeList){
if(item.tksType == eve.key){
item.tksType = eve.value
}
}
}
this.dataList = data;
this.total = response.total;
this.loading = false;
});
},
這樣就會依次向下執行代碼
二: 補充
PS: map foreach 等帶有回調函數的都是異步函數,盡量少用,可以用for of 代替,因為for of就是一個簡單的循環,不會帶有回調。