我使用ais-instant-search和ais-state-results来显示我的数据。我将结果隐藏到query.length > 0。它可以工作,但如果我不输入任何搜索字符串,它总是显示一条消息。下面是我的代码和截图:

<ais-state-results>
<p slot-scope="{ query, hits }" v-if="!hits.length">
Not found for: <q>{{ query }}</q>
</p>
<template v-else slot-scope="{ query }">
<ais-hits v-if="query.length > 0">
<template slot="item"
slot-scope="{ item }"
>
<h1>
<ais-highlight
:hit="item"
attribute="name"
/>
</h1>
<ul>
<li>{{ item.price }}</li>
</ul>
</template>
</ais-hits>
</template>
</ais-state-results>发布于 2019-06-10 22:03:45
小部件包含a fallback content,它在默认插槽为空时呈现(这是您给出的屏幕截图)。一旦应用程序启动,你在示例中编写的两个条件都是假的。由于槽中没有渲染任何内容,因此默认渲染会生效。当所有条件都不满足时,您可以使用空的div来解决此问题。下面是一个示例:
<ais-state-results>
<template slot-scope="{ query, hits }">
<!-- First condition -->
<p v-if="!hits.length">Not found for: <q>{{ query }}</q></p>
<!-- Second condition -->
<ais-hits v-else-if="query" />
<!-- Fallback condition -->
<div v-else />
</template>
</ais-state-results>你可以在CodeSandbox上找到一个活的例子。
https://stackoverflow.com/questions/56333189
复制相似问题