es6 switch case regex
es6 switch case 正则
regex – Switch statement for string matching in JavaScript – Stack Overflow
javascript switch case 的case能用正则表达式吗?? – 知乎
js 2015 switch case regex
New regular expression features in ECMAScript 6
regex – Switch statement for string matching in JavaScript – Stack Overflow
【总结】
总之是:
js的官网的switch case中,就没有正则的写法
网友虽然可以写出switch case中带正则,但是不建议用。
所以改为if else去吧:
parsePageType(currentUrl){ let pageType = ROUTER_PAGE.NONE; if (currentUrl === `${ENV_PREFIX}/`) { currentTitle = "首页"; … } else if (currentUrl === `${ENV_PREFIX}/pregnancyManagement`) { currentTitle = "孕检管理"; } else if (currentUrl.match(`${ENV_PREFIX}/pregnancyProcess`)) { currentTitle = "填写处理详情"; … currentTitle = "牛舍编辑"; } else if (currentUrl.match(`${ENV_PREFIX}/cowshedEditAdd/2`)) { currentTitle = "新增牛舍"; } return pageType; } |
转载请注明:在路上 » 【无法解决】ES6中如何写switch case且带正则匹配