update 优化 findPathNum 方法 更高效

This commit is contained in:
疯狂的狮子Li 2025-03-19 10:30:14 +08:00
parent 48e9f2c5c0
commit fba121f5c3

View File

@ -40,13 +40,8 @@ const getBreadcrumb = () => {
levelList.value = matched.filter((item) => item.meta && item.meta.title && item.meta.breadcrumb !== false);
};
const findPathNum = (str, char = '/') => {
let index = str.indexOf(char);
let num = 0;
while (index !== -1) {
num++;
index = str.indexOf(char, index + 1);
}
return num;
if (typeof str !== 'string' || str.length === 0) return 0;
return str.split(char).length - 1;
};
const getMatched = (pathList, routeList, matched) => {
let data = routeList.find((item) => item.path == pathList[0] || (item.name += '').toLowerCase() == pathList[0]);