Skip to content

Commit b59eae5

Browse files
author
lishiwen
committed
renderSlots
1 parent 4a3000f commit b59eae5

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

example/slots-simple/Slot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { h } from "../../lib/m-vue.esm.js";
1+
import { h, renderSlots } from "../../lib/m-vue.esm.js";
22

33
export default {
44
render() {
55
const originalContent = h("div", {}, "这是原来的内容");
6-
return h("div", {}, [originalContent, this.$slots]);
6+
return h("div", {}, [originalContent, renderSlots(this.$slots)]);
77
},
88
setup() {},
99
};

lib/m-vue.cjs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const ComponentPublicInstanceHandlers = {
191191
};
192192

193193
function initSlots(instance, instanceChildren) {
194-
instance.slots = instanceChildren || [];
194+
instance.slots = isArray(instanceChildren) ? instanceChildren : [instanceChildren];
195195
}
196196

197197
function promiseEmit() { }
@@ -329,10 +329,15 @@ function h(type, props, children) {
329329
return createVNode(type, props, children);
330330
}
331331

332+
function renderSlots(slots) {
333+
return createVNode('span', null, slots);
334+
}
335+
332336
exports.createApp = createApp;
333337
exports.createComponentInstance = createComponentInstance;
334338
exports.createVNode = createVNode;
335339
exports.h = h;
336340
exports.patch = patch;
337341
exports.render = render;
342+
exports.renderSlots = renderSlots;
338343
exports.setupComponent = setupComponent;

lib/m-vue.esm.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const ComponentPublicInstanceHandlers = {
187187
};
188188

189189
function initSlots(instance, instanceChildren) {
190-
instance.slots = instanceChildren || [];
190+
instance.slots = isArray(instanceChildren) ? instanceChildren : [instanceChildren];
191191
}
192192

193193
function promiseEmit() { }
@@ -325,4 +325,8 @@ function h(type, props, children) {
325325
return createVNode(type, props, children);
326326
}
327327

328-
export { createApp, createComponentInstance, createVNode, h, patch, render, setupComponent };
328+
function renderSlots(slots) {
329+
return createVNode('span', null, slots);
330+
}
331+
332+
export { createApp, createComponentInstance, createVNode, h, patch, render, renderSlots, setupComponent };

src/runtime-core/componentSlots.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isArray } from "../shared/type";
2+
13
export function initSlots(instance, instanceChildren) {
2-
instance.slots = instanceChildren || [];
3-
}
4+
instance.slots = isArray(instanceChildren) ? instanceChildren : [instanceChildren];
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createVNode } from "../createVNode";
2+
3+
export function renderSlots(slots) {
4+
return createVNode('span', null, slots);
5+
}

src/runtime-core/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export * from "./createApp";
22
export * from "./createVNode";
33
export * from "./component";
44
export * from "./render";
5-
export * from "./h"
5+
export * from "./h"
6+
export * from "./helper/renderSlots";

0 commit comments

Comments
 (0)