【发布时间】:2021-12-23 22:26:16
【问题描述】:
我有一个将插槽作为输入的Tabpane 组件。从模板导入时,它按预期工作。
<Tabpane>
<div caption="I am div 1">Div 1</div>
<div caption="I am div 2">Div 2</div>
</Tabpane>
但是,当从其他组件(示例中为 Composite)导入时,会触发以下警告:
Slot "default" invoked outside of the render function:
this will not track dependencies used in the slot. Invoke the slot function inside the render function instead.
// src/components/Composite.js
import { defineComponent, h } from "vue";
import Tabpane from "./Tabpane.vue";
export default defineComponent({
name: "Composite",
setup() {
const slots = [
h("div", { caption: "I am div 1" }, ["Div 1"]),
h("div", { caption: "I am div 2" }, ["Div 2"])
];
return () => h(Tabpane, {}, () => slots);
}
});
【问题讨论】:
标签: vue.js vuejs3 vue-composition-api slots