小编hyp*_*hor的帖子

“默认插槽遇到非功能值。” 在 Vue 3 Composition API 组件中

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使用并填充其槽:HelloWorldsetup

// 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)

slots vue.js vuejs3 vue-composition-api

17
推荐指数
1
解决办法
1万
查看次数

Vue 3 cli-service 应用程序:当从其他组件导入带有插槽的组件时,出现“在渲染函数之外调用插槽“默认””警告

MCVE

我有一个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)

slots vue.js vuejs3 vue-composition-api

3
推荐指数
1
解决办法
8270
查看次数

标签 统计

slots ×2

vue-composition-api ×2

vue.js ×2

vuejs3 ×2