gpt4 book ai didi

javascript - 如果插槽未从父级传递,则进行条件渲染

转载 作者:搜寻专家 更新时间:2023-10-30 22:44:47 25 4
gpt4 key购买 nike

以下面的代码为例:

<header>
<slot name='header'></slot>
<template v-if='?'>
<h1>{{ someInput }}</h1>
</template>
</header>

我想显示 <h1>{{ some input }}</h1>如果没有任何东西通过插槽。我可以使用什么作为 v-if 中的条件?

最佳答案

这就够了:

<header>
<slot name='header'>
<h1>{{ someInput }}</h1>
</slot>
</header>

Anything originally inside the tags is considered fallbackcontent. Fallback content is compiled in the child scope and will onlybe displayed if the hosting element is empty and has no content to beinserted.

来自 docs .

关于javascript - 如果插槽未从父级传递,则进行条件渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42974854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com