条件判断的性能优化

条件判断的性能优化

if(){
}else if(){
}else
直接略过,不建议。。。

switch (this.currentWrite) {
   case '项目经理初审':
     this.form.pmFirstApprovalPersion = res.data.name
     break;
   case '执行部门审核1':
     this.form.execDeptApprovePerson1 = res.data.name
     break;
   case '总经理审批':
     this.form.gmApprovePerson = res.data.name
     break;
   case '远程服务-预判':
     this.form.remoteFieldServiceExecutor = res.data.name
     break;
   case '执行部门审核2':
     this.form.execDeptSecondServicePerson2 = res.data.name
     break;
   case '现场执行2':
     this.form.fieldExecContactPerson2 = res.data.name
     break;
   case '执行部门审核3':
     this.form.execDeptApprovalPerson3 = res.data.name
     break;
   case '申请人确认':
     this.form.applyerConfirmPerson = res.data.name
     break;
   case '备案':
     this.form.filingPerson = res.data.name
     break;
   default:
     this.form.filingPerson2 = res.data.name
     break;
 }

虽然用switch性能比较好,但是明显很烦,我们可以用数组的形式来优化

const obj =  [
            '项目经理初审',
            '执行部门审核1',
            '总经理审批':2,
            '远程服务-预判',
            '执行部门审核2',
            '现场执行2',
            '执行部门审核3',
            '申请人确认',
            '备案'
            ]
const arr = [
                this.form.pmFirstApprovalPersion,
                this.form.execDeptApprovePerson1,
                this.form.gmApprovePerson,
                this.form.remoteFieldServiceExecutor,
                this.form.execDeptSecondServicePerson2,
                this.form.fieldExecContactPerson2,
                this.form.execDeptApprovalPerson3,
                this.form.applyerConfirmPerson,
                this.form.filingPerson,
                this.form.filingPerson2,
            ]           

        arr[obj.indexOf([this.currentWrite])+1 ?
        obj.indexOf([this.currentWrite]) : arr.length-1
        ] = res.data.name
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值