🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
>[info] 遍历children形式数据 ~~~ /** * 遍历children形式数据 * @param data 需要遍历的数组 * @param callback 回调 * @param childKey children字段名 */ export function eachTreeData(data, callback, childKey = 'children') { if (!data || !data.length) { return; } data.forEach((d) => { if (callback(d) !== false && d[childKey]) { eachTreeData(d[childKey], callback, childKey); } }); } ~~~ ~~~ computed: { // 权限树选中数据 checked() { let checked = []; this.$util.eachTreeData(this.authData, d => { if (d.checked && (!d.children || !d.children.length)) { checked.push(d.id); } }); return checked; } }, ~~~