MCVE
https://github.com/hyperbotauthor/minvue3cliapp
MCVE 直播
https://codesandbox.io/s/white-browser-fl7ji
我有一个 Vue 3 cli-service 应用程序,它使用带有插槽的组合 API 组件。
该HelloWorld
组件渲染它在 a 中接收到的槽div
:
// src/components/Helloworld.js
import { defineComponent, h } from "vue";
export default defineComponent({
setup(props, { slots }) {
return () => h("div", {}, slots);
}
});
Run Code Online (Sandbox Code Playgroud)
该组件在其功能中Composite
使用并填充其槽:HelloWorld
setup
// src/components/Composite.js
import { defineComponent, h } from "vue";
import HelloWorld from "./HelloWorld";
export default defineComponent({
setup(props, { slots }) {
return () =>
h(HelloWorld, {}, [h("div", {}, ["Div 1"]), h("div", …
Run Code Online (Sandbox Code Playgroud) 我有一个Tabpane
将插槽作为输入的组件。从模板导入后,它会按预期工作。
<Tabpane>
<div caption="I am div 1">Div 1</div>
<div caption="I am div 2">Div 2</div>
</Tabpane>
Run Code Online (Sandbox Code Playgroud)
但是,当从其他组件导入时(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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)