let a = 'aa', curIndex = 1
if(a = 'aa'){
} else if (a === "bb") {
curIndex = 2;
} else if (a === "cc") {
curIndex = 3;
} else if (a === "dd") {
curIndex = 4;
} else if (a === "ee") {
curIndex = 5;
} else if (a === "ff") {
curIndex = 6;
} else if (a === "gg") {
curIndex = 7;
} else {
curIndex = -1;
}
// 优化
const obj = {
"aa": 1,
"bb": 2,
"cc": 3,
"dd": 4,
"ee": 5,
"ff": 6,
"gg": 7,
};
let path = router.currentRoute.value.path;
curIndex = obj[path as keyof typeof obj] || -1;
if else 多层嵌套优化
最新推荐文章于 2024-03-21 13:49:26 发布