在vscode中eslint報(bào)錯(cuò)

eslint報(bào)map返回值錯(cuò)誤
查了下文檔,map是需要返回值的。

map文檔
看了文檔瞬間醒悟,將之前代碼重寫
//創(chuàng)建list,push進(jìn)list
const list = [];
state.brandList.map(item => {
if (!item.children) {
list.push(item);
return false;
}
item.children.map(i => {
if (i.label === action.payload.label) {
i.children = action.payload.children;
list.push(item);
return false;
}
return i;
});
return list;
});
// 利用返回值重寫后代碼更加簡潔
const list = state.brandList.map(item => {
if (!item.children) return item;
item.children.map(i => {
if (i.label === action.payload.label) {
i.children = action.payload.children;
}
return i;
});
return item
});

創(chuàng)建的json結(jié)構(gòu)

創(chuàng)建的json結(jié)構(gòu)