[{
path: '/demand',
name: 'demand',
meta: {
icon: '_xuqiu',
title: '需求'
},
component: Main,
children: [{
path: 'my_demand',
name: 'my_demand',
meta: {
icon: '_icon_xuqiushenpi',
title: '我的需求单'
},
component: () => import('@/view/demand/my_demand.vue')
},
{
path: 'materiel_demand',
name: 'materiel_demand',
meta: {
icon: '_wuliaox',
title: '物料需求单'
},
component: () => import('@/view/demand/materiel_demand.vue')
}]
}]
可以根据下面的my_demand,改名对应上面的title吗?如上面的name为my_demand的meta的title改为1
let json = [{
'my_demand': '1',
}, {
'materiel_demand': '2',
}]
###const jsonMap = json.reduce((map, it) => {
Object.keys(it)
.forEach(key => map[key] = it[key]);
return map;
}, {});
data
.flatMap(m => m.children)
.forEach(m => {
const title = jsonMap[m.name];
if (title) {
m.meta.title = title;
}
});
console.log(jsonMap);
console.log(JSON.stringify(data, null, 2));
###let _json = json.reduce((obj, cur) => {
let key = Object.keys(cur)[0];
obj[key] = cur[key];
return obj;
}, {});
function replaceObj(arr = []) {
return arr.map(item => {
if (_json[item.name]) {
item.meta.title = _json[item.name];
}
if (item.children) {
item.children = replaceObj(item.children);
}
return item;
});
}
console.log(replaceObj(data));