优化页面
This commit is contained in:
28
components/addPrefixToHeaderIcon.js
Normal file
28
components/addPrefixToHeaderIcon.js
Normal file
@@ -0,0 +1,28 @@
|
||||
function addPrefixToHeaderIcon(data) {
|
||||
// 处理数组:递归处理每个元素
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach(item => addPrefixToHeaderIcon(item));
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理对象:递归处理每个属性
|
||||
if (typeof data === 'object' && data !== null) {
|
||||
for (const key in data) {
|
||||
if (key === 'headerIcon' ||key === 'anchorIcon' && data.hasOwnProperty(key)) {
|
||||
// 在headerIcon值前添加前缀(处理各种类型)anchorIconA anchorIconB anchorIcon
|
||||
const value = data[key];
|
||||
data[key] = "https://vv-1317974657.cos.ap-shanghai.myqcloud.com/headerIcon/" + (
|
||||
typeof value === 'string' ? value
|
||||
: value != null ? String(value)
|
||||
: ""
|
||||
);
|
||||
} else if (typeof data[key] === 'object' && data[key] !== null) {
|
||||
// 递归处理嵌套对象或数组
|
||||
addPrefixToHeaderIcon(data[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
export default addPrefixToHeaderIcon;
|
||||
Reference in New Issue
Block a user