Skip to content

Commit

Permalink
support scope slot
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Oct 27, 2021
1 parent 61e4a2e commit 106cac0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/runtime-core/componentSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export function initSlots(instance, children) {
}
}

const normalizeSlotValue = (value) => {
// 把 function 返回的值转换成 array ,这样 slot 就可以支持多个元素了
return Array.isArray(value) ? value : [value];
};

const normalizeObjectSlots = (rawSlots, slots) => {
for (const key in rawSlots) {
const value = rawSlots[key];
Expand All @@ -17,7 +22,7 @@ const normalizeObjectSlots = (rawSlots, slots) => {
// 后续在 renderSlots 中调用
// TODO 这里没有对 value 做 normalize,
// 默认 slots 返回的就是一个 vnode 对象
slots[key] = value;
slots[key] = (props) => normalizeSlotValue(value(props));
}
}
};

0 comments on commit 106cac0

Please sign in to comment.