会比if else简介很多,逻辑也会更清楚
// 两位补零操作
handleZeroFill(val,item){
switch(item) {
case 'openCircuitVoltage':
this.form.openCircuitVoltage = Number(val).toFixed(2);
break;
case 'shortCircuitCurrent':
this.form.shortCircuitCurrent = Number(val).toFixed(2);
break;
case 'ratedOperationalVoltage':
this.form.ratedOperationalVoltage = Number(val).toFixed(2);
break;
case'ratedOperationalCurrent':
this.form.ratedOperationalCurrent = Number(val).toFixed(2);
break;
default:
this.form.test = 'this is a default'
}
},
?case 'openCircuitVoltage': 就等于 if(item === 'openCircuitVoltage'){}