vue async/await同步 案例

async function handler() {
await validateParams();
const dbResults = await dbQuery();
const results = await serviceCall(dbResults);
console.log(results);
return results;
}

 https://www.cnblogs.com/jiangds/p/9139743.html

    // 备件借出/归还-扫码备件编码后
    function lentAdd(event,type) {
        var evt = arguments[0] || window.event;
        if (evt.keyCode == 13) {
            this.lentAlertReset();
            debugger;
            //初始化维护数据
            this.$http.post('/ToolingBasicInfo/GetToolingInfo',
                {
                    TOOLING_BARCODE: this.lentCommonForm.TOOLING_BARCODE,
                    ACTION_TYPE: type,
                    models: this.lentTableData,
                },
                { emulateJSON: true }
            ).then(function (res) {
                if (res.data.ReturnResult == '0') {
                    if (res.data.ReturnValue.TOOLING_ID == null) {
                        this.showMessage('lent', 'error', '@StringResource.Tooling_NotExist');
                    }
                    else {
                        if (this.checkLentAdd(res.data.ReturnValue)) {
                            this.showMessage('lent', 'error', '@StringResource.Tooling_lent_isExist');
                        }
                        else {
                            //this.lentTableData.push(res.data.ReturnValue);
                            //--------------借出时验证-------------------------lh
                            if (type == 1) {
                                var tooling_model = res.data.ReturnValue.TOOLING_MODEL;
                                var tooling_type = res.data.ReturnValue.TOOLING_TYPE;
                                console.log("call this.VerityModels(" + tooling_model + ", " + tooling_type+")");
                                this.VerityModels(tooling_model, tooling_type).then(ok => {
                                    console.log("VerityModels return: " + ok);
                                    if (ok) {
                                        this.lentTableData.push(res.data.ReturnValue);
                                    }
                                });
                            } else if (type == 2) {
                                this.lentTableData.push(res.data.ReturnValue);
                            }
                            //-------------------------------------------------
                        }
                    }
                } else {
                       this.showMessage('lent', 'error', res.data.ReturnMessage);
                }
            }, function () {
                this.showMessage('error', '@SEMI.TMS.Resources.StringResource.Sys_ExeFail');
                });

           this.lentCommonForm.TOOLING_BARCODE = '';
        }
    }
    // 利用备件型号、备件类型、客户代号、产品型号和封装形式去ToolingModel表验证lh
    async function VerityModels(tooling_model, tooling_type) {
        debugger;
        console.log("VerityModels start.");
        var flag = false;
        if (this.lentCommonForm.PRODUCT_NAME == null || this.lentCommonForm.PRODUCT_NAME == '') {
            this.showMessage('lent', 'error', '产品型号不存在,请联系系统管理员。');
        }
        // 同步,否则返回值会出错
        await this.$http.post('VerityModels',
                {
                    tooling_model: tooling_model,
                    tooling_type: tooling_type,
                    cust_name: this.lentCommonForm.CUST_NAME,
                    product_name: this.lentCommonForm.PRODUCT_NAME,
                    package_type: this.lentCommonForm.PACKAGE_TYPE,
                },
                { emulateJSON: true }
            ).then(function (res) {
                if (res.data.ReturnResult == '0') {
                    console.log("VerityModels res.data.ReturnResult: " + res.data.ReturnResult);
                    flag = true;
                } else {
                    this.showMessage('lent', 'error', '备件型号信息不匹配,请联系备件库维护备件型号。');
                }
            }, function () {
                this.showMessage('error', '@SEMI.TMS.Resources.StringResource.Sys_ExeFail');
            });
        debugger;
        return flag;
    }
原文地址:https://www.cnblogs.com/ggsddu/p/12560347.html